Branch: refs/heads/main
Revision: 691814f
Author: e-kayrakli
Link: Allow compile-time indexing for param strings and bytes by e-kayrakli · Pull Request #19702 · chapel-lang/chapel · GitHub
Log Message:
Merge pull request #19702 from e-kayrakli/param-string-index
Allow compile-time indexing for param strings and bytes
With this PR, indexing string
and bytes
using []
or .item
is a
compile-time operation. As such, the results of such operations can be stored in
param
s.
Copying from that issue, the following is legal with this PR:
param s = "chapel";
param i = 1;
param ss = s[i]; // this was not a compile time operation
compilerWarning(ss);
Implementation details:
- Adds two primitives
PRIM_STRING_ITEM
andPRIM_BYTES_ITEM
- These primitives are post-folded into string or bytes symbols respectively.
- This involves some refactoring in postfold to reuse some of the existing
logic used for post-foldingPRIM_ASCII
. - Adds
chpl_enc_codepoint_at_idx
to in the shared runtime header to support
thePRIM_STRING_ITEM
primitive.
[Reviewed by @mppf]
Test:
-
[x] standard linux64
Modified Files:
A test/types/string/param-index-bytes-item.good
A test/types/string/param-index-bytes.good
A test/types/string/param-index-string.good
A test/types/string/param-index.chpl
A test/types/string/param-index.compopts
A test/types/string/param-index.noexec
M compiler/AST/primitive.cpp
M compiler/dyno/include/chpl/uast/prim-ops-list.h
M compiler/resolution/postFold.cpp
M modules/internal/Bytes.chpl
M modules/internal/String.chpl
M runtime/include/encoding/encoding-support.h
M test/parsing/stringLiteralIndex/stringBytesLiteralIndexOOB1.good
M test/parsing/stringLiteralIndex/stringBytesLiteralIndexOOB2.goodCompare: Comparing e2137e1ed125...691814f0cfc6 · chapel-lang/chapel · GitHub