如何使用@GrailsTypeChecked 和@GrailsCompileStatic
How to use @GrailsTypeChecked and @GrailsCompileStatic
我有兴趣了解 Grails 中的新注释,理论上应该提供运行时性能改进,同时仍然允许动态调度,但它似乎没有效果。我错过了什么?
class MyService {
@GrailsTypeChecked // or @GrailsCompileStatic
def doSomething() {
String name = missingVariable
}
}
grails> clean
| Application cleaned.
grails> compile
| Compiling 1 source files.....
一切都编译但在运行时爆炸?我一定是遗漏了什么,因为我真的不明白这些新注释是如何工作的。编译器将如何确定什么是错误调用以及什么是可以忽略的错误调用(即动态查找器)?
我正在使用 Grails 2.5.0
该代码不应编译。我已经构建了一个简单的应用程序并将您的代码直接粘贴到该应用程序中,但代码无法为我编译。参见 https://github.com/jeffbrown/grailscompilestatic。
| Compiling 8 source files
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] /Users/jeff/t/grailscompilestatic/grails- app/services/demo/MyService.groovy: 9: [Static type checking] - The variable [missingVariable] is undeclared.
[groovyc] @ line 9, column 19.
[groovyc] String name = missingVariable
[groovyc] ^
[groovyc]
| Compiling 8 source files.
| Error Compilation error: startup failed:
/Users/jeff/t/grailscompilestatic/grails-app/services/demo/MyService.groovy: 9: [Static type checking] - The variable [missingVariable] is undeclared.
@ line 9, column 19.
String name = missingVariable
^
1 error
How will the compiler be able to work out what is a bad call and what
is a bad call that can be ignored (i.e. a dynamic finder)?
我们有与类型检查器协作的类型检查扩展程序,因此当类型检查器认为它看到无效代码时,我们的扩展程序就会参与进来,如果扩展程序能够识别出它有点像动态查找器,不能静态调度,但实际上在运行时有效。
根据 Jeff 的评论,似乎有一个错误阻止了 @GrailsCompileStatic 和 @GrailsTypeChecked 注释在 class 级别 @Transactional 注释也存在时工作。我相信这现在已在 grails 3.0.1 中修复(谢谢大家!)
我有兴趣了解 Grails 中的新注释,理论上应该提供运行时性能改进,同时仍然允许动态调度,但它似乎没有效果。我错过了什么?
class MyService {
@GrailsTypeChecked // or @GrailsCompileStatic
def doSomething() {
String name = missingVariable
}
}
grails> clean
| Application cleaned.
grails> compile
| Compiling 1 source files.....
一切都编译但在运行时爆炸?我一定是遗漏了什么,因为我真的不明白这些新注释是如何工作的。编译器将如何确定什么是错误调用以及什么是可以忽略的错误调用(即动态查找器)?
我正在使用 Grails 2.5.0
该代码不应编译。我已经构建了一个简单的应用程序并将您的代码直接粘贴到该应用程序中,但代码无法为我编译。参见 https://github.com/jeffbrown/grailscompilestatic。
| Compiling 8 source files
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] /Users/jeff/t/grailscompilestatic/grails- app/services/demo/MyService.groovy: 9: [Static type checking] - The variable [missingVariable] is undeclared.
[groovyc] @ line 9, column 19.
[groovyc] String name = missingVariable
[groovyc] ^
[groovyc]
| Compiling 8 source files.
| Error Compilation error: startup failed:
/Users/jeff/t/grailscompilestatic/grails-app/services/demo/MyService.groovy: 9: [Static type checking] - The variable [missingVariable] is undeclared.
@ line 9, column 19.
String name = missingVariable
^
1 error
How will the compiler be able to work out what is a bad call and what is a bad call that can be ignored (i.e. a dynamic finder)?
我们有与类型检查器协作的类型检查扩展程序,因此当类型检查器认为它看到无效代码时,我们的扩展程序就会参与进来,如果扩展程序能够识别出它有点像动态查找器,不能静态调度,但实际上在运行时有效。
根据 Jeff 的评论,似乎有一个错误阻止了 @GrailsCompileStatic 和 @GrailsTypeChecked 注释在 class 级别 @Transactional 注释也存在时工作。我相信这现在已在 grails 3.0.1 中修复(谢谢大家!)