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.

hsutter and others added 30 commits May 20, 2024 21:37
… case bugs

On my machine, with this commit here are some typical cppfront compile time data points:
- `reflect.h2`: 0.5s
- `pure2-last-use.cpp2`: 0.3s
- all 134 regression tests: 6.3s

When I added the optimization to cache results of calls to g_d_o and checked the results to make sure they were unchanged, I noticed that in fact g_d_o was occasionally returning different answers in different calls for the same arguments. All the examples I found were corner cases in `pure2-last-use.cpp2`. The lookup bugs I found are now fixed in this commit.

This commit moves the `-_debug` command line flag from reporting stack instrumentation to reporting things I'm now coding here: Now using that flag will check the g_d_o results computed with vs. without the two new optimizations and ensure the answers are the same. (Disclaimer: Because this exercise led to a few bug fixes, which were applied to both the old and new functions, this isn't quite identical to comparing it to the true "old" way which contained a couple of I-think-innocuous-but-now-fixed bugs. The proof of the pudding is in the regression tests being identical.)
… investigation

Timers now run only in `-_debug` since they slow things down

`-_debug` now implies `-verbose`

`-verbose` now sorts the timer output in descending cost order
Signed-off-by: Neil Henderson <2060747+bluetarpmedia@users.noreply.github.com>
`ubuntu-latest` is an alias/pointer which over time changes and points at newer ubuntu images. Different ubuntu images have different compiler versions installed and newer images drop older compiler versions. So to keep the CI builds running successfully it's better to use explicit version requirements.

Signed-off-by: Neil Henderson <2060747+bluetarpmedia@users.noreply.github.com>
And improve timer performance by removing `make_shared`
…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>
hsutter and others added 30 commits March 2, 2025 15:24
By bringing in @MaxSagebaum's current autodiff code + just rename one unused parameter to _ to keep a clean build at high warning levels

Also fix a bug where a nonempty blank line was being considered a violation of -pure-cpp2
Style note: I'm currently trying to follow the pattern of choosing ".get_Y" vs. ".as_Y" names as follows...

"get": X::is_Y / X::get_Y pairs
   - when Y is conceptually "NOT all of" the X
   - for example, expression_statement::get_expression because even though the expression is most of the statement the expression-statement contains that extra `;` and is at a different conceptual layer

"as": X::is_Y / X::as_Y pairs
   - when Y is conceptually "all of" the X
   - for example, statement::as_expression_statement because it's really still the whole statement
   - with the idea that this could legitimately become an actual `as` operator

I may not be 100% consistent on that right now, but I think the current API is pretty close to that
For now a string is likely sufficient

We can make this a meta::literal reflection type in the future if that's needed
* #1376: Fix crash on non-constructor with 'out this'

* #1376: Add regression test.

* Minor tidying

Removed the eliminated assert

Re-ran regression tests

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* Fix bug #1378 and create a regression test.

* Renamed new test file to *-error.cpp2

---------

Co-authored-by: Herb Sutter <herb.sutter@gmail.com>
* 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>
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.