src/compiler/translator/ImmutableString.h


Log

Author Commit Date CI Message
Kimmo Kinnunen 8e9dc1a6 2024-11-19T11:08:31 Validate anonymous struct names with namespace Consider GLSL: struct { vec4 e; } g; struct sbbf { vec4 f; }; The struct name validation would fail if user chosen struct name would clash with a symbol name that ANGLE internally gave to an anonymous struct. Fix by importing Name abstraction from MSL backend. A symbol name is a pair (namespace, string). Move operator<<(std::ostream &os, const ImmutableString &str) to sh namespace because that is more natural for operator overloading name resolution. MSVC works with this. Bug: angleproject:379758201 Change-Id: Icc9b02aa8cb532e1d925e2fba4c45468f01b9144 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6035029 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Kimmo Kinnunen <kkinnunen@apple.com>
Shahbaz Youssefi 96f44329 2024-03-25T14:16:10 Revert "Remove few redundant ImmutableString to std::string conversions" This reverts commit ebb94b807f184f2d36cb0843c429667cd80e0675. Reason for revert: Needs a different implementation of std::string::size() to pass C++17 compilers. Original change's description: > Remove few redundant ImmutableString to std::string conversions > > Maybe removes few strlen calls. > > Bug: angleproject:8614 > Change-Id: I4fbb5f6abb8e8d21ff44a34975bab379127a0a11 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5372715 > Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> > Commit-Queue: Geoff Lang <geofflang@chromium.org> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> > Reviewed-by: Geoff Lang <geofflang@chromium.org> Bug: angleproject:8614 Change-Id: I1a635b74674a2e1b635972bb4372c43340527a2f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5391900 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Roman Lavrov 0197826b 2024-03-22T14:42:34 Revert "Add conversion operator from ImmutableString to std::string" This reverts commit 8c0dae388bccb00f11cd94d641d719cc68325826. Reason for revert: Breaks Android rolls: external/angle/src/compiler/translator/ImmutableString.h:103:15: error: constexpr function's return type 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char>>') is not a literal type 103 | constexpr operator std::string() const { return std::string(data(), length()); } | ^ external/libcxx/include/string:4332:64: note: 'basic_string<char>' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors 4332 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>) Original change's description: > Add conversion operator from ImmutableString to std::string > > Also use the operator in a couple of places. Sometimes saves a strlen. > > Bug: angleproject:8614 > Change-Id: I429f3ac02af04b568ac7d1adf22ab65e5007fbda > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5372728 > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> > Commit-Queue: Geoff Lang <geofflang@chromium.org> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Bug: angleproject:8614 Change-Id: I46963686f9506f7029e164250b1bf81f8ab2c519 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5388255 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Roman Lavrov <romanl@google.com>
Kimmo Kinnunen 8c0dae38 2024-03-15T16:09:04 Add conversion operator from ImmutableString to std::string Also use the operator in a couple of places. Sometimes saves a strlen. Bug: angleproject:8614 Change-Id: I429f3ac02af04b568ac7d1adf22ab65e5007fbda Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5372728 Reviewed-by: Geoff Lang <geofflang@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Kimmo Kinnunen ebb94b80 2024-03-16T09:11:51 Remove few redundant ImmutableString to std::string conversions Maybe removes few strlen calls. Bug: angleproject:8614 Change-Id: I4fbb5f6abb8e8d21ff44a34975bab379127a0a11 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5372715 Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Kimmo Kinnunen c5f7bbeb 2024-03-15T19:03:24 Make ImmutableString::beginsWith constexpr Maybe reduces strlen calls. Bug: angleproject:8614 Change-Id: Ic63d019c185db7acde2c2645c499b5408ec23b78 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5372122 Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Kimmo Kinnunen 0ad73958 2024-03-04T11:17:36 Deduplicate and fix ConstStrLen implementations Move multiple implementations to one angle::ConstStrLen. Some of the implementations were partially incorrect, too. Fixed: angleproject:8569 Change-Id: I760c173a5b75932f4ae2fabcc4916329247d3cb5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5332384 Commit-Queue: Kenneth Russell <kbr@chromium.org> Auto-Submit: Kimmo Kinnunen <kkinnunen@apple.com> Reviewed-by: Kenneth Russell <kbr@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Clemen Deng 56db3789 2019-08-01T17:09:53 Use flat arrays instead of switches for function lookups Current implementation of built in function lookup uses autogenerated switch statements. Instead, use the perfect hash mapping to have the lookup use arrays instead. This will improve runtime performance. Bug: angleproject:3805 Change-Id: I6d0ba62d79abd53a7fe818fe675282800781f256 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1756883 Commit-Queue: Clemen Deng <clemendeng@google.com> Reviewed-by: Geoff Lang <geofflang@chromium.org>
Stuart Morgan 9d737966 2019-08-14T12:25:12 Standardize copyright notices to project style For all "ANGLE Project" copyrights, standardize to the format specified by the style guide. Changes: - "Copyright (c)" and "Copyright(c)" changed to just "Copyright". - Removed the second half of date ranges ("Y1Y1-Y2Y2"->"Y1Y1"). - Fixed a small number of files that had no copyright date using the initial commit year from the version control history. - Fixed one instance of copyright being "The ANGLE Project" rather than "The ANGLE Project Authors" These changes are applied both to the copyright of source file, and where applicable to copyright statements that are generated by templates. BUG=angleproject:3811 Change-Id: I973dd65e4ef9deeba232d5be74c768256a0eb2e5 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1754397 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Jamie Madill b980c563 2018-11-27T11:34:27 Reformat all cpp and h files. This applies git cl format --full to all ANGLE sources. Bug: angleproject:2986 Change-Id: Ib504e618c1589332a37e97696cdc3515d739308f Reviewed-on: https://chromium-review.googlesource.com/c/1351367 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Jamie Madill b779b12c 2018-06-20T11:46:43 Add kEmptyImmutableString. We can use this instead of ImmutableString(""). Bug: angleproject:2665 Change-Id: I8b3d5d3075838b9f2caa1627071202e48a5fdc83 Reviewed-on: https://chromium-review.googlesource.com/1108085 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Luc Ferron <lucferron@chromium.org>
Olli Etuaho 89398b65 2018-03-21T17:30:50 Avoid mangled name comparisons of 3-parameter functions The hash values used for looking up built-ins now encode whether the mangled name contains arrays, structs or interface blocks in its parameters list. This is written in the most significant bit of the hash value. We check this bit at the start of built-in lookup and if the bit is set we exit early. After that we know that the lookup name doesn't contain array, struct or interface block parameters. When we find a hash that matches a hash of a built-in function, we now know 3 things: 1) the length of the mangled name matches 2) the open parentheses in the mangled name matches 3) the lookup doesn't contain array, struct or block parameters. Additionally, we have an if statement checking whether the function name matches. Collisions are only possible with functions that 1) have the same name 2) have the same number of parameters With these preconditions we can check beforehand whether collisions are possible for 3-parameter functions. If there are no collisions, we don't need to compare the full mangled name. This is similar to what was already being done with functions that had 0 to 2 parameters. This reduces shader_translator binary size by around 4 KB on Windows. Besides increased complexity, the tradeoff is that an exhaustive search of hash values for possible 3-parameter combinations is costly, so the gen_builtin_functions.py code generation script now takes around one minute to run on a high-end workstation. Due to this, the script now exits early if it detects it has already been run with the same inputs based on a hash value stored in builtin_symbols_hash_autogen.txt. BUG=angleproject:2267 BUG=chromium:823856 TEST=angle_unittests Change-Id: I3ff8c6eb85b90d3c4971ac8d73ee171a07a7e55f Reviewed-on: https://chromium-review.googlesource.com/973372 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 3b678745 2018-03-21T12:59:19 Use a specialized hash function for mangled names The hash values used for looking up built-ins now encode the string length and the location of parentheses as six-bit values, so that we don't need to check for these if the hash matches. This decreases shader_translator binary size on Windows by around 10 KB. BUG=angleproject:2267 BUG=chromium:823856 TEST=angle_unittests Change-Id: If8c28e1c8851750633509ec6273f556e06e91cd1 Reviewed-on: https://chromium-review.googlesource.com/973243 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho c4bd0ac9 2018-02-22T16:29:32 Add 32-bit hash helper to ImmutableString Since the length of the hash is known prior to compilation, it can be compared with script-generated hashes. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ia0a78dfd450c4ea2d526da7f3495b9750dcbd1af Reviewed-on: https://chromium-review.googlesource.com/931884 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Olli Etuaho 7b17fa18 2018-01-29T11:12:57 Add a constexpr constructor for TVariable BUG=angleproject:2267 TEST=angle_unittests Change-Id: I9b7e01801caa7235ac5e2d4212ea92e38c1f774d Reviewed-on: https://chromium-review.googlesource.com/908752 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho fbb1c792 2018-01-19T16:26:59 Store symbol names as a ImmutableString This will enable compile-time initialization of built-in symbols as well as reducing copying strings. Most of the code that deals with names is changed to use ImmutableString where it makes sense to avoid conversions. The lexer/parser now allocate const char pointers into pool memory instead of allocating TStrings. These are then converted to ImmutableString upon entering TParseContext. BUG=angleproject:2267 TEST=angle_unittests, angle_end2end_tests Change-Id: I244d6271ea1ecf7150d4f89dfa388a7745a1150c Reviewed-on: https://chromium-review.googlesource.com/881561 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Olli Etuaho 12c03761 2018-01-25T12:22:33 Resubmit: Use ImmutableString for HLSL texture references This fixes an issue in the original revision of this patch by adding a operator<< to TInfoSinkBase that takes ImmutableString as a parameter. This also adds ImmutableStringBuilder class, which can be used to build ImmutableStrings in place without extra allocations if the maximum length is known in advance. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I52e984657a3aba3e6fe67a82b401c6b8de557d18 Reviewed-on: https://chromium-review.googlesource.com/890522 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Jamie Madill d1434c04 2018-01-29T02:29:53 Revert "Use ImmutableString for HLSL texture references" This reverts commit c13bda8678e86ff75a4acfc94f7a45e58224926d. Reason for revert: May have broken LibFuzzer and AFL builds: https://ci.chromium.org/buildbot/chromium.fyi/Afl%20Upload%20Linux%20ASan/7718 https://build.chromium.org/deprecated/chromium.fyi/builders/Libfuzzer%20Upload%20Linux%20ASan/builds/8691 In file included from ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.cpp:12: In file included from ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.h:19: ../../third_party/angle/src/compiler/translator/InfoSink.h:40:16: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup stream << t; ^ ../../third_party/angle/src/compiler/translator/TextureFunctionHLSL.cpp:111:9: note: in instantiation of function template specialization 'sh::TInfoSinkBase::operator<<<sh::ImmutableString>' requested here out << textureReference; ^ ../../third_party/angle/src/compiler/translator/ImmutableString.h:76:15: note: 'operator<<' should be declared prior to the call site or in namespace 'sh' std::ostream &operator<<(std::ostream &os, const sh::ImmutableString &str); ^ 1 error generated. Bug: chromium:806619 Original change's description: > Use ImmutableString for HLSL texture references > > This also adds ImmutableStringBuilder class, which can be used to > build ImmutableStrings in place without extra allocations if the > maximum length is known in advance. > > BUG=angleproject:2267 > TEST=angle_unittests > > Change-Id: I4dfb78adeb0cffcfad0d25753fb8063466012c92 > Reviewed-on: https://chromium-review.googlesource.com/886362 > Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> > Reviewed-by: Jamie Madill <jmadill@chromium.org> TBR=jmadill@chromium.org,cwallez@chromium.org,oetuaho@nvidia.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: angleproject:2267 Change-Id: I445f5a786f8b16c3f40f28df09d45fcb215a9c88 Reviewed-on: https://chromium-review.googlesource.com/890542 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
Olli Etuaho c13bda86 2018-01-25T12:22:33 Use ImmutableString for HLSL texture references This also adds ImmutableStringBuilder class, which can be used to build ImmutableStrings in place without extra allocations if the maximum length is known in advance. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I4dfb78adeb0cffcfad0d25753fb8063466012c92 Reviewed-on: https://chromium-review.googlesource.com/886362 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
Olli Etuaho 2d8e432a 2018-01-22T14:12:46 Add ImmutableString to encapsulate some compiler strings The new ImmutableString class is intended to be used instead of plain const char pointers to pool-allocated or static memory. It has the following advantages over using plain const char pointers: 1. It makes it clear when a string is guaranteed to be safe to pass around inside the compiler. 2. It can be compared with a comparison operator rather than using strcmp, which is easier to read. 3. It records the length of the stored string, which enables faster copies and comparisons in some cases. 4. ImmutableStrings could be implicitly converted from std::strings when a pool-allocated string is required. This is robust and convenient. C++17 has a similar class std::string_view, but our code style doesn't allow it yet. We also couldn't use it as is if we require properties 1 and 4 from above, but would rather need to inherit or wrap it in a custom class. Eventually all current usage of TString could be replaced with ImmutableString. For now, use it for unmangled built-in names. TEST=angle_unittests BUG=angleproject:2267 Change-Id: Id60c7b544032e06460e1b99837e429bc84dc4367 Reviewed-on: https://chromium-review.googlesource.com/881020 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>