[squeak-dev] The Trunk: Tests-eem.497.mcz
commits at source.squeak.org
commits at source.squeak.org
Fri Jan 13 01:03:48 UTC 2023
Eliot Miranda uploaded a new version of Tests to project The Trunk:
http://source.squeak.org/trunk/Tests-eem.497.mcz
==================== Summary ====================
Name: Tests-eem.497
Author: eem
Time: 12 January 2023, 5:03:46.05687 pm
UUID: 4ac1c0d8-40ce-438b-932a-6f2a64d106b8
Ancestors: Tests-tpr.496
Fix the Compiler max literals tests in the wake of Compiler-eem.483
=============== Diff against Tests-tpr.496 ===============
Item was changed:
----- Method: CompilerTest>>testMaxLiterals (in category 'tests - limits') -----
testMaxLiterals
"Document the maximum number of literals in a compiled method"
+ | bytecodeSetEncoder maxLiterals stringThatCanBeCompiled stringWithOneTooManyLiterals |
- | maxLiterals stringThatCanBeCompiled stringWithOneTooManyLiterals |
"Why 6? It's rather implementation dependent. But the {... construct is compiled as
(Array braceStream: size)
nextPut: expr;
...;
braceArray
+ where nextPut: is a special selector. So one each for Array binding, #braceStream, #braceArray and possibly the size,
+ one for the selector and one for the methodClass makes 5 or 6."
+ bytecodeSetEncoder := CompiledCode preferredBytecodeSetEncoderClass new.
+ maxLiterals := bytecodeSetEncoder maxNumLiterals - 6.
+ "If the bytecode set can push the size of the brace stream with a bytecode (not needing a literal) then we need one more literal."
+ (bytecodeSetEncoder isSpecialLiteralForPush: maxLiterals) ifTrue:
+ [maxLiterals := maxLiterals + 1].
- where nextPut: is a special selector. So one each for Array binding, #braceStream, #braceArray and the size,
- one for the selector and one for the methodClass makes 6."
- maxLiterals := CompiledCode preferredBytecodeSetEncoderClass new maxNumLiterals - 6.
stringThatCanBeCompiled := '{ ', (String streamContents: [:strm |
1 to: maxLiterals do: [:e | strm nextPutAll: '''', e asString, '''', ' . ']]), '}'.
stringWithOneTooManyLiterals := '{ ', (String streamContents: [:strm |
1 to: maxLiterals + 1 do: [:e | strm nextPutAll: '''', e asString, '''', ' . ']]), '}'.
self assert: ((1 to: maxLiterals) collect: #printString) equals: (Compiler evaluate: stringThatCanBeCompiled).
"If the following test fails, it means that the limit has been raised or eliminated,
and this test should be updated to reflect the improvement."
self should: [Compiler evaluate: stringWithOneTooManyLiterals] raise: Error.
!
Item was changed:
----- Method: CompilerTest>>testMaxLiteralsWithClassReferenceInClosure (in category 'limits') -----
testMaxLiteralsWithClassReferenceInClosure
"Document the maximum number of literals in a compiled method. A class
reference in a closure reduces the maximum literals."
| bytecodeSetEncoder maxLiterals stringThatCanBeCompiled stringWithOneTooManyLiterals |
bytecodeSetEncoder := CompiledMethod preferredBytecodeSetEncoderClass new.
maxLiterals := bytecodeSetEncoder maxNumLiterals
- 2 "for selector & methodClass"
- (bytecodeSetEncoder supportsFullBlocks ifTrue: [1] ifFalse: [5 "For this example. See below"])
- 4 "for the implicit stream processing into which the brace construct is compiled: (Array braceStream: size) braceArray".
+ "If the bytecode set can push the size of the brace stream with a bytecode (not needing a literal) then we need one more literal."
+ (bytecodeSetEncoder isSpecialLiteralForPush: maxLiterals) ifTrue:
+ [maxLiterals := maxLiterals + 1].
stringThatCanBeCompiled := '[ DateAndTime now. Date today. Time ]. { ',
(String streamContents: [:strm |
1 to: maxLiterals do: [:e | strm nextPutAll: '''', e asString, '''', ' . ']]), '}'.
stringWithOneTooManyLiterals := '[ DateAndTime now. Date today. Time ]. { ',
(String streamContents: [:strm |
1 to: maxLiterals + 1 do: [:e | strm nextPutAll: '''', e asString, '''', ' . ']]), '}'.
self assert: maxLiterals equals: (Compiler evaluate: stringThatCanBeCompiled) size.
"If the following test fails, it means that the limit has been raised or eliminated,
and this test should be updated to reflect the improvement."
self should: [Compiler evaluate: stringWithOneTooManyLiterals] raise: Error.
!
More information about the Squeak-dev
mailing list
|