Skip to content

Conversation

@jarzec
Copy link
Owner

@jarzec jarzec commented Jan 17, 2024

This is a PR pulling hsutter/main into a local branch.
The goal is to never actually merge the PR, but to get notifications when regression tests fail on hsutter/main.

bluetarpmedia and others added 30 commits May 24, 2024 10:42
…f applicable) the standard library to link with (#1080)

* Regression test jobs now specify the C++ standard version and (if applicable) the standard library to link with

* Add a new job to test clang with libc++ on ubuntu. (All other ubuntu jobs for gcc & clang link with libstdc++.)

* Add a new msvc job so that we now test `c++latest` and `c++20`.

* Job names now include more information:
<short os name> | <compiler> | <c++ std> | <std library> | <full os name>

* Reorder jobs so that GCC are first, then clang on ubuntu & macOS, and then msvc on Windows

e.g.
ubu-24 | g++-14 | c++2b | libstdc++ | ubuntu-24.04
mac-13 | clang++ | c++2b | default | macos-13
win-22 | cl.exe | c++latest | default | windows-2022

* Update msvc test bat files
Build declaration_starts as we go, instead of rebuilding it in pieces later - I may get rid of it entirely later in favor of a better optimization I'm thinking about, but at least now while we have it this is a cleaner way to build it

Also make global_token_counter a sema member - part of getting rid of static variables so that compiling more than one file on the same cppfront command line starts fresh each time (there are a few more statics to go)
After a couple of passes of optimizing get_declaration_of to make its traversal of the symbol table more efficient, I decided to rewrite it entirely to build the information during the initial visitation and not scour at the symbol table afterwards to rediscover the information.

The code generation for all `*.cpp2` and `*.h2` files in the project is unchanged, so it seems likely that this rewrite is not introducing bugs. If we do find some, they should be easier to fix as the lookup logic is now more direct and built and consumed in just two places.

To prevent accidental behavior change, I exhaustively checked every call to get_declaration_of to check whether it returned a different result before and after this change. There were quite a few during debugging which pointed out where I'd overlooked a lookup case, and those are now all fixed. There remained only a few (<10) calls in this entire corpus where g_d_o is now giving a different result, but all are cases where g_d_o was not being consistent previously (repeated calls with the same arguments in the same execution sometimes gave a result and sometimes gave null) and it's now giving the same answer consistently that it gave "sometimes" before. So I think this change is fixing those as (latent) bugs... latent because the compilation output before/after is unchanged, because the previous inconsistency was in cases that didn't actually affect compilation behavior.
Signed-off-by: gregmarr <gregmarr@users.noreply.github.com>
* cpp2::move is now constexpr

* Add `inline` too

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* Add `..` syntax to select a member function only

With this commit, `x.f()` is still UFCS, but `x..f()` will now find only a member function.

For now I like that the default is UFCS, but as we get more experience I'm open to changing the default so that `.` is member selection and `..` is UFCS (which would be a breaking change, but a mechanical one).

Also: Remove the old version of `get_declaration_of` now that the new lookup seems stable.

* Remove some debug code

* Finish removing old g_d_o paths
* prohibit semicolons in parameter list

* Formatting tweak: `{}` around branch bodies, 4-space indent

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* Default initialize function argument

* Add output to test to show that defaults were applied

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* CI Aggreate generated patches

* CI Reactivate Windows regression tests

* Ci Update C++20 test on Windows

* CI exclude lines with Windows paths from git

* CI Update mixed-default-arguments.cpp2 test
…s of phase

Closes #1124
Closes #1123

I think the key #1123 and #1124 are exposing is that we shouldn't be continuing past the point where sema checks fail (we already know there's an error), but we aren't doing the sema checks purely because declarations are multi-phase so I only call the checks on phase 2 to avoid duplicate error messages... but that means that in the other phases we're not doing the checks and continuing as if the code is legal.

So here's an update to ensure the checks are always called so that the function won't continue if errors have already been found, but we still only actually emit the errors in phase 2. It's slightly wasteful to write duplicate messages to a local container, but hey, it only happens if there are error messages and there shouldn't be large numbers of them.
Signed-off-by: gregmarr <gregmarr@users.noreply.github.com>
Fix two places where peek(i)->something was not first checking that peek(i) was non-null, to avoid ICEs near the end of the source file
* cli: Add command '-cwd' (change working directory).

* Tweak to strip leading path always, so that the `.cpp2` source file path is stripped

In addition to enabling `-cwd` behavior, this will change the default to put files in the current directory even if a pathname is used to refer to a file in another directory (this default behavior will be overridden by `-o` or `-cwd` if specified)

* Remove stray `;;` for clean builds

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
hsutter and others added 30 commits April 28, 2025 19:37
* Three more fuzz crashes.

* Add regression test for crash 10.

* Error instead of crash if users write silly things in aliases.

* Fix assertion on comments near end of file.

* Disallow declarations of parents after functions.

* Fix more fuzz crashes.

* Rename error test cases to `*-error.cpp2`

* Minor tidying to fit house style

`exit(1)` -> `exit(EXIT_FAILURE)`

Branch and loop bodies are always enclosed in `{` `}` even when they contain a single line

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* CI: Replace Clang-18 with CLang-19

* CI: Fix pure Cpp2 regression tests for MSVC
Only generate other operator= functions from (out this, that) if _none_ of the other three were written - generate all of them or none of them

Remove the "A2" generation arrow, which also removes a potential second path to a generated (inout this, move that) via both M2 and A2 where M2 was already preferred - this removes the need for a tie-break and embraces the already-preferred path

The previous rule did not allow for expressing copy/move-constructible types that are not assignable (rare, but can happen when there are const members or Cpp1 reference members) - that can now be expressed by writing two operator='s, (out this, that) and (out this, move that)
Like copyable, but only construction, not assignment
Thanks to Jeroen Van Antwerpen for reminding me that it is possible to have a polymorphic type that is copyable/movable (in fact, I do that a lot in the Cpp2 reflection API), and so it makes sense for an @interface to have _protected_ copying functions - this way the interface is not copyable by default (correct), but a type that implements the interface has the option of defining copy/move if it wants to

Made @interface generate protected copy/move construction/assignment

Similarly, removed the restriction that @polymorphic_base types cannot be copyable

Made operator= "A1" generation work also for polymorphic types - until now it was restricted to only monomorphic types, but it really should work anytime operator= exists - this permits @interface to just define the general operator= as per usual Cpp2 style and get all four functions

No change to the "A3" rule, that tends to work great for non-polymorphic types - but while doing this PR I tried applying it also to polymorphic types and noticed it would frequently cause problems in the presence of polymorphic base types, so leaving A3 alone seems useful and right

Made the polymorphic reflection API types @copy_constructible instead of @copyable so as not to require generating assignment (they are current inherently non-assignable because some members are not assignable)
* CI: Fix Windows build command in build workflow

* CI: Update regression test results
…tements)

Added tests

Added sample code that traverses function bodies including if branches

That's most of it... the main thing to reflect next is loops, and then a few smaller things like using statements and inspect statements
Also made parameter attributes accessible
Also add expression[_node]::is_assignment_expression for symmetry, even though currently expression-nodes have no other alternatives (they could grow try-expressions in the future)

Cleanup: Remove old autodiff stub code which I think is no longer being used / needed for reference - Max please let me know if that's not so
…tialized locals

The reason to initialize in declaration order is for things that depend on nested lifetime, which is common for local variables – such as a smart pointer variable followed by another variable whose delayed initialization depends on the smart pointer being constructed and keeping something alive. That doesn’t apply to return values.
Supports this code:

widget: @python type
= {
    value: int;
    operator=: (out this, i: int) = { value = i; }

    add: (inout this, i: int) -> int
        = { value += i; return value; }

    shout: (this, s: std::string) -> std::string
        = s + "!";
}

Being invoked from Python like this:

import widgetlib

w = widgetlib.widget(10)
print(w.add(5))         # prints 15
print(w.add(i=7))       # prints 22
print(w.shout("hello")) # prints "hello!"

I'm not checking in a test case though because this is proof-of-concept only, currently hardwired to generate pybind11 and bash .sh invoking g++-10
* Update for regex 20 lookbehind test.

Removed cpp file and added cpp2 file.

* Fix for name lookup issues with MSVC.

* Add missing files.

* Refactor of autodiff with generalized traversal.

Added test for autodiff.

* Handling of expression lists.

* Handling of expresson terms.

* Handling of function calls.

* Added special handling of math functions.

* Added declarations and statements to simple_traversal.

* Handling if/else statements.

* Added handling of direct return.

* Stub handling of value declarations.

* Added example for non differential variable.

* Added handling of while and do while loops.

* Handling of for loops and added special functions.

* Unified function call handling.

* Proper handling of initializer expressions.

* Fix initializer problem.

* Suffix can now be user defined.

* Added second order test.

* Remove initialization order workaround.

* Taylor polynomial propagation implementation.

* Basic handling of higher order derivatives and handling of add and minus.

* Added  handling for multiply and division.

* Higher order handling for special functions.

* Remaining tests for higher order derivatives.

* Declaration lookup and lookup of function return name.

* Basic changes for adding new things for the differentiation.

* Moved handling of types and functions to autodiff_declaration_handler.

* Added handling for differentiation of symbols outside of metafunction type declaration.

* Basic differentation for type and namespace value declarations.

* Refactor of autodiff_expression_handler.

The expression handler no longer generates the assignments. It stores
the primal and forward expression. The assignments can now be generated
with helper functions or by accessing the expressions.

* Handling of member access.

* Moved assignment handling code to proper traverse function.

* Added type differentiation for types without member functions.

* Handling of member function calls.

First basic setup for declared variable lookup.

* Handling of prefix + and -.

* Basic preperations for reverse mode AD.

* Refactor of diff string to structure.

Currently placeholder that defaults to the forward derivatives.

* Reverse handling of function declaration.

* Reverse differentiation of additive expressions.

* Basic handling of multiplication and division.

* Fix for to_string of expressions.

* Activity analysis for variables and functions.

* Update for tests and acitivity analysis.

* Added tests for combined binary expressions.

* Handling of special functions for reverse mode.

* Added handling of function calls for reverse.

* Handling of statement parameters for loops in forward mode.

* Reverse handling of for loops.

* Temp.

* Build clean with GCC 10 and Clang 21, and update regression test results

* Bugfix for passive variables in addition or subtraction statements.

* Add an AD unit test

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* Documentation for autodiff.

* Fix remarks and build errors.

* Trying to fix msvc.

* Update results for regression tests.

* Make AD warning be not an error so regression tests run

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* Add runtime check for modulo by zero

* Rerun regression tests

One of the tests now hits an MSVC error I've seen before, related to using std::source_location via module std import -- it doesn't manifest on any other compiler, or in MSVC using std headers. So the error is spurious, but I'm not able to debug it or find a workaround, and I don't want to record regression test failures just because of that use case where 'module std currently doesn't work.' So this commit also changes all -pure regression tests to use headers, not modules, at least for now until modules work better

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* CI Update runners in the build-cppfront.yaml

* CI Update runners in the regression-tests.yml

* CI Use -include-std cppfront option for pure regression tests
Including regression test cases

TODO: write docs

Basic usage is

    try {
        ...
    }
    catch( i: int ) { use(i); } // catch an int
    catch( _ ) { } // catch everything
And bump build number
And 'encapsulated' and 'noncopyable' metaclasses
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.