jdaugherty commented on PR #3084:
URL: https://github.com/apache/groovy/pull/3084#issuecomment-6931817145

   Thanks, Paul. I took the proposal as written. For item 2 I kept one default 
everywhere and documented GSE instead. The branch is rebased on master, and the 
new commits are `cafadeda54` (option, lookup and tests) and `3b35ce66af` 
(notes). The 6.0.x port branch has the same change.
   
   **Loader history.** Agreed: it applies with or without sources, so I've 
dropped it as an argument. The notes now say that a reused `GroovyShell` or 
GSE, groovysh and the console can resolve a name to a class that the loader 
compiled earlier. With `defaultPackageSources=false` this goes away as well, 
since the class-file lookup doesn't use `loadClass`. 
`testClassCompiledEarlierByTheClassLoader` covers it.
   
   **1. `defaultPackageSources`.** 
`CompilerConfiguration.DEFAULT_PACKAGE_SOURCES` (`defaultPackageSources`, 
system property `groovy.resolve.default.package.sources`) is on unless set to 
`false`, and ignored when `defaultPackageFirst` is `false`. When it is `false`, 
`resolveFromDefaultPackage` calls a new package-private 
`ClassNodeResolver.resolveClassFile`. That method reuses the existing 
`readClassFile`: `loader.getResource(name + ".class")`, then `new 
DecompiledClassNode(AsmDecompiler.parseClass(url), new 
AsmReferenceResolver(this, compilationUnit))`, with the same name-mismatch 
check.
   - A hit goes through `cacheClass`.
   - A miss is not cached as `NO_CLASS`. It goes into a separate set in the 
resolver, so a name that occurs many times in one unit doesn't call 
`getResource` each time, and the later `resolveToOuter` still finds a sibling 
source after the default imports 
(`testDefaultPackageSourceFoundWithoutSources`).
   - It doesn't go through `findClassNode`, so GSE's override and its roots are 
not involved.
   
   I counted `ResourceConnector` calls for a GSE script that uses 12 
default-import types: 76 with the sources on, 52 with them off, and 52 with 
`defaultPackageFirst=false`. That matches your two extra lookups per type, and 
none with the sources off.
   
   **2. GSE default.** I kept one default everywhere. Having GSE resolve the 
same script differently from `groovyc` seemed worse than documenting the 
behaviour. A GSE-only default would also have to copy the caller's 
`CompilerConfiguration` in `ScriptClassLoader` for every compile, to avoid 
changing a configuration it doesn't own. `COMPATIBILITY.md` describes the mixed 
results, the stale results until the engine is recreated, and the two extra 
root lookups per name, with `defaultPackageSources=false` as the remedy. 
`testScriptEngineRootSource` checks both: by default the root's `Date`, with 
the sources off `java.util.Date`.
   
   **3. Gradle.** Agreed. The Groovy 7 entry now says an incremental Gradle 
build gives the same result either way, and gives the route 
`groovyOptions.optimizationOptions['defaultPackageSources']`.
   
   **4. Tests.** With the sources off, `Groovy12555` now covers:
   - a compiled class, which still comes before the default import;
   - a sibling source, which now comes after it;
   - a sibling source whose name isn't a default import, which is still found;
   - a nested class.
   
   It also adds the GSE case and the `GroovyShell` loader case, and 
`CompilerConfigurationTest` covers the new system property. The tests for the 
sibling source, GSE and the loader fail without the change. Core `:test` passes 
locally on both branches.
   
   **5. Notes.** The Groovy 7 and 6.0.1 entries in `COMPATIBILITY.md` and the 
note in `core-program-structure.adoc` now cover the option and the cases above. 
In the 6.0.x port both options are off unless set to `true`, so 
`defaultPackageFirst=true` alone gives the class-file-only lookup there. That 
is enough for the Gradle case.
   
   **6. Housekeeping.** Rebased on current master. In both conflicts, 
`COMPATIBILITY.md` and the system-property table, I kept both sides. The 6.0.x 
port is rebased on `GROOVY_6_0_X` as well.
   
   @daniellansun, could you take another look? Since your approval there's the 
nested-name commit (`289dfdeca2` after the rebase, `b96fa00c30` before it) and 
the two commits above.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to