Skip to content

Spock-Compiler does not use wrapper types anymore - #1765

Merged
leonard84 merged 3 commits into
spockframework:masterfrom
AndreasTu:CondRewriter_Primitive
Sep 15, 2023
Merged

leonard84 merged 3 commits into
spockframework:masterfrom
AndreasTu:CondRewriter_Primitive

Conversation

@AndreasTu

Copy link
Copy Markdown
Member

Changed the usages of ConstExpressions to use primitive type where possible.

Previously the generated code was:

ICONST_4
INVOKESTATIC Integer.valueOf (I)L/Integer;
INVOKEVIRTUAL Integer.intValue ()I
INVOKEVIRTUAL ValueRecorder.startRecordingValue (I)I

Now it is simply:

ICONST_4
INVOKEVIRTUAL ValueRecorder.startRecordingValue (I)I

@AndreasTu AndreasTu self-assigned this Aug 15, 2023
@codecov

codecov Bot commented Aug 15, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 89.61% and no project coverage change.

Comparison is base (d660020) 79.82% compared to head (1cf92b1) 79.83%.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1765   +/-   ##
=========================================
  Coverage     79.82%   79.83%           
- Complexity     4079     4083    +4     
=========================================
  Files           425      425           
  Lines         12914    12953   +39     
  Branches       1630     1641   +11     
=========================================
+ Hits          10309    10341   +32     
- Misses         1998     2000    +2     
- Partials        607      612    +5     
Files Changed Coverage Δ
...ock/util/SourceToAstNodeAndSourceTranspiler.groovy 78.02% <78.94%> (+0.01%) ⬆️
...main/java/org/spockframework/compiler/AstUtil.java 80.53% <100.00%> (+0.94%) ⬆️
...org/spockframework/compiler/ConditionRewriter.java 90.23% <100.00%> (ø)
...g/spockframework/compiler/InteractionRewriter.java 91.79% <100.00%> (ø)
...ava/org/spockframework/compiler/SpecAnnotator.java 97.19% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonard84
leonard84 requested a review from Vampire August 21, 2023 18:32
leonard84
leonard84 previously approved these changes Aug 21, 2023
Vampire
Vampire previously approved these changes Aug 22, 2023

@Vampire Vampire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, thanks.
Could you maybe add some tests that verify the outcome?
You can look for usages of Snapshotter on how to do it.

@AndreasTu

Copy link
Copy Markdown
Member Author

@Vampire I have added the tests.
The tests need to track the bytecode, because the normal AST representation does not show the wrapper usage. So I needed more code to make that happen.

Vampire
Vampire previously approved these changes Aug 23, 2023

@Vampire Vampire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thanks

AndreasTu and others added 3 commits September 15, 2023 12:00
Changed the usages of ConstExpressions to use primitive
type where possible.

Previously the generated code was:
ICONST_4
INVOKESTATIC Integer.valueOf (I)L/Integer;
INVOKEVIRTUAL Integer.intValue ()I
INVOKEVIRTUAL ValueRecorder.startRecordingValue (I)I

Now it is simply:
ICONST_4
INVOKEVIRTUAL ValueRecorder.startRecordingValue (I)I

SourceToAstNodeAndSourceTranspiler now also supports to trace out
the generated bytecode.
@leonard84
leonard84 force-pushed the CondRewriter_Primitive branch from f40e29e to 1cf92b1 Compare September 15, 2023 10:00
Comment on lines +73 to +78
boolean shallTraceBytecode = compilePhase >= CompilePhase.CLASS_GENERATION.phaseNumber
if (shallTraceBytecode) {
cu.setClassgenCallback(createClassgenCallback(writer, showSet))
} else {
cu.addPhaseOperation(new AstNodeToScriptVisitor(writer, showSet), compilePhase)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have some impact on https://gwc-experiment.appspot.com/ as that is the default phase that is pre-selected, .

@leonard84
leonard84 merged commit 7b8863a into spockframework:master Sep 15, 2023
leonard84 added a commit that referenced this pull request Sep 15, 2023
in #1765 the behavior of the SourceToAstNodeAndSourceTranspiler was
changed, so that it would output bytecode instructions when the
`CLASS_GENERATION` compile phase was used.
This was problematic as the SourceToAstNodeAndSourceTranspiler is also
used in the Groovy Web Console, and the `CLASS_GENERATION` phase still
had transformations that affected the source and would have not been
accessible anymore. Now we moved the bytecode output trigger to the
`OUTPUT` phase, while internally clamping the actual compiler phase to
the `CLASS_GENERATION` phase.
@AndreasTu
AndreasTu deleted the CondRewriter_Primitive branch September 15, 2023 17:36
@leonard84 leonard84 added this to the 2.4-M2 milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants