Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapting jsiek's executable semantics tooling for commit. #237

Merged
merged 31 commits into from
Feb 19, 2021
Merged

Adapting jsiek's executable semantics tooling for commit. #237

merged 31 commits into from
Feb 19, 2021

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jan 13, 2021

Notes versus what jsiek wrote:

  • This adopts Bazel for building.
    • System-local versions of bison/flex are used. I found https://github.com/jmillikin/rules_bison, but those print a lot of warnings (things like -Wsign-compare IIRC) which makes builds hard to read. Plus I think the underlying bison_cc_library rule didn't work, so this would really only get a hermetic bison/flex build (helpful, but didn't seem worth more time).
    • I'm adding in a .bazeliskrc to push a somewhat more standard choice of bazel versions. I noticed I was getting unstable versions by default, possible Google-specific, but seemed good to include.
    • The -lpthread kludge.
  • Turn all of the examples into golden tests.
    • Including adding a golden test rule.
  • Fixed various style guide issues. For example:
  • Dropped using of std names -- I believe this is preferred (maybe we should be explicit about this in the Carbon style guide)
  • Switched enum uses to enum class for ease-of-identification.
  • Spent some time breaking out files to hopefully be easier to read/edit pieces, and understand relations between structs.
  • Added code requires to syntax.ypp to address include issues

Possibly other things -- but the fundamental structure is, I believe, unchanged. I put in the golden tests pretty early to ensure I wasn't mutating output/results.

@google-cla google-cla bot added the cla: yes PR meets CLA requirements according to bot. label Jan 13, 2021
@jonmeow jonmeow mentioned this pull request Jan 13, 2021
Copy link

@dabrahams dabrahams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! But please add instructions for building and running with Bazel. A naïve attempt yields:

$ bazel test
Loading: 
Loading: 0 packages loaded
DEBUG: Rule 'rules_foreign_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "1dbab600e91d3fe2c9ff1baaf2bec929e8ffbf7e81f6b501e52783c86614bf83"
DEBUG: Call stack for the definition of repository 'rules_foreign_cc' which is a http_archive (rule definition at /private/var/tmp/_bazel_dabrahams/309deff96dbfdff03fd99c86c609773c/external/bazel_tools/tools/build_defs/repo/http.bzl:292:16):
 - /Users/dabrahams/src/carbon-semantics/WORKSPACE:11:1
ERROR: no such package '@llvm_bazel//': The repository's path is "third_party/llvm-bazel/llvm-bazel" (absolute: "/Users/dabrahams/src/carbon-semantics/third_party/llvm-bazel/llvm-bazel") but this directory does not exist.
ERROR: no such package '@llvm_bazel//': The repository's path is "third_party/llvm-bazel/llvm-bazel" (absolute: "/Users/dabrahams/src/carbon-semantics/third_party/llvm-bazel/llvm-bazel") but this directory does not exist.
INFO: Elapsed time: 0.102s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Couldn't start the build. Unable to run tests
FAILED: Build did NOT complete successfully (0 packages loaded)

Note: I really am that naïve; i.e. it's not obvious to me what to do to make this work.

@jonmeow
Copy link
Contributor Author

jonmeow commented Jan 29, 2021

I'm discussing the build issues with dabrahams separately -- this was an issue with missing git submodules, but there's other issues. However, contribution tools docs are intended to address the underlying "get tools working" issue.

@dabrahams
Copy link

I am still unable to get this to build on any platform, even after following all the contribution tools instructions

@jonmeow
Copy link
Contributor Author

jonmeow commented Feb 5, 2021

@dabrahams Not sure if you missed my response over IM (I responded about 15 minutes before you commented here), but "bison: command not found" means you don't have bison installed. If you're not familiar with bison, see here. The dependency is noted in the PR description: "System-local versions of bison/flex are used".

Regardless, please note I'm just assuming you're commenting on the same build error that you did over IM. When you run into errors, it would really be more constructive to provide the errors that you're running into. That would also give others a chance to comment and debug without a round of "what error are you seeing?"

@dabrahams
Copy link

dabrahams commented Feb 5, 2021 via email

@dabrahams
Copy link

OK, thanks for the hints so far. On Linux, I got this to work:

~/go/bin/bazelisk test --repo_env=CC=$HOME/src/carbon-lang/third_party/llvm-project/build/bin/clang :all

After installing flex and bison with apt. Don't try to install them with brew unless you want to wait "forever."

On Mac, we have:

bazelisk test --repo_env=CC=$HOME/src/carbon-lang/third_party/llvm-project/build/bin/clang :all
Loading: 
Loading: 0 packages loaded
Analyzing: 62 targets (0 packages loaded, 0 targets configured)
INFO: Analyzed 62 targets (1 packages loaded, 120 targets configured).
INFO: Found 33 targets and 29 test targets...
bazel: Entering directory `/private/var/tmp/_bazel_dabrahams/7eb59300bade26410e9aa17cfd0b52e9/execroot/carbon/'
[0 / 8] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /Users/dabrahams/src/carbon-lang/executable_semantics/ast/BUILD:26:11: Compiling executable_semantics/ast/expression_or_field_list.cpp [for host] failed: (Exit 1): clang++ failed: error executing command /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/clang++ -Wall -Wextra -Wthread-safety -Wself-assign -Wno-unused-parameter -Wno-missing-field-initializers -fcolor-diagnostics -MD -MF ... (remaining 26 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox clang++ failed: error executing command /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/clang++ -Wall -Wextra -Wthread-safety -Wself-assign -Wno-unused-parameter -Wno-missing-field-initializers -fcolor-diagnostics -MD -MF ... (remaining 26 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from executable_semantics/ast/expression_or_field_list.cpp:5:
In file included from ./executable_semantics/ast/expression_or_field_list.h:8:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/list:185:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/memory:670:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/typeinfo:61:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/exception:81:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/__memory/base.h:14:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/__debug:14:
In file included from /Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/iosfwd:95:
/Users/dabrahams/src/carbon-lang/third_party/llvm-project/build/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~

@jonmeow
Copy link
Contributor Author

jonmeow commented Feb 5, 2021

Just a reminder, the C++ toolchain doesn't support Mac yet...

@dabrahams
Copy link

FWIW, on Mac, with or without trunk merged into this, I still can't build, and I don't understand the meaning of the errors:

bazelisk test :all
Loading: 
Loading: 0 packages loaded
DEBUG: Rule 'rules_foreign_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "8d465a001bfb689c177db7b29485e83bd2109df386b3727d29d3444ded946c8f"
DEBUG: Repository rules_foreign_cc instantiated at:
  /Users/dabrahams/src/carbon-lang/WORKSPACE:11:13: in <toplevel>
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_dabrahams/7eb59300bade26410e9aa17cfd0b52e9/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
Analyzing: 62 targets (0 packages loaded, 0 targets configured)
INFO: Analyzed 62 targets (0 packages loaded, 0 targets configured).
INFO: Found 33 targets and 29 test targets...
bazel: Entering directory `/private/var/tmp/_bazel_dabrahams/7eb59300bade26410e9aa17cfd0b52e9/execroot/carbon/'
[0 / 9] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ERROR: /Users/dabrahams/src/carbon-lang/executable_semantics/BUILD:40:8: Executing genrule //executable_semantics:syntax_bison_srcs [for host] failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
executable_semantics/syntax.ypp:5.1-5: invalid directive: `%code'
executable_semantics/syntax.ypp:5.7-9: syntax error, unexpected identifier
bazel: Leaving directory `/private/var/tmp/_bazel_dabrahams/7eb59300bade26410e9aa17cfd0b52e9/execroot/carbon/'

flex and bison are installed, FWIW.

@jonmeow
Copy link
Contributor Author

jonmeow commented Feb 10, 2021

@dabrahams It looks like you're getting a parse error indicating an old version bison. xcode installs bison 2.3 (from 2006); please make sure you are using a recent version.

@dabrahams
Copy link

@jonmeow thanks for the hint; I'll look into it. I thought I installed bison with brew but maybe it's getting bypassed.

FWIW, I successfully built on linux after merging trunk into this branch.

@jonmeow
Copy link
Contributor Author

jonmeow commented Feb 11, 2021

Per brew output on mac you need to add bison and flex on your path because they're trying not to conflict with system binaries, e.g.:

export PATH="/Users/jperkins/.brew/opt/bison/bin:$PATH"
export PATH="/Users/jperkins/.brew/opt/flex/bin:$PATH"

copts = [
"-Wno-unneeded-internal-declaration",
"-Wno-unused-function",
"-Wno-writable-strings",
Copy link

@dabrahams dabrahams Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-Wno-writable-strings",
"-Wno-writable-strings",
"-std=c++14",

Without this change, uses of the "register" keyword in the bison output go from being warnings to being errors on MacOS.

With this change, and brew's bison first in the path, I can report success on MacOS!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion on Discord, I'm wary of this fix because it feels like a broad stroke. I think it'd probably be better to investigate options further, but I'd rather not block commit on this as the current state works for Linux.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take the broad stroke now to unblock Mac users (including the original author of the code) and open an issue to find a better fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To validate, I successfully built on mac with no changes. I do get a register-related build error if I use an older version of flex, the one included by xcode.

As I previously noted, a recent version of flex is required, just as with bison. Please ensure you're using a recent version.

I think we need to be really cautious about changing how builds work; it can become more difficult to fix later. While I think no change should be needed here, in the future, please provide build errors and rationale for changing code. Sometimes, by thinking these issues through, we can get to the root of the issue and arrive at a different solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the diligent work. It didn't occur to me that the old flex was the cause, but that explains everything.

Copy link
Contributor

@jsiek jsiek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good. Thanks Jon!

@jonmeow jonmeow requested a review from a team February 17, 2021 17:58
Copy link

@dabrahams dabrahams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as an initial commit.

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for all the fixes here!

@jonmeow jonmeow merged commit 2111b85 into carbon-language:trunk Feb 19, 2021
@jonmeow jonmeow deleted the executable-semantics branch February 19, 2021 23:25
@dabrahams
Copy link

@jonmeow Thank you for all your work getting this landed. It's going to make a huge difference going forward.

dabrahams pushed a commit that referenced this pull request Feb 28, 2021
* Add assertion to detect UB in interpreter.cpp

This change, applied to 2111b85 ("Adapting jsiek's executable semantics tooling
for commit. (#237)"), causes the if2.6c test to segfault.  Becase the assertion
fires only when `stmt == nullptr` and no code has permission to change `stmt`
(it is `const`) before it is dereferenced in the `switch`, and nothiing in
`PrintStatement` is supposed to exit the program, the assertion is a valid
change that detects a bug.

The crash was originally manifest in 0213c6d ("Executable Semantics: 1st-class
stacks (#296)").

* Temporarily disable the if2 test pending #311

See #311

* [executable semantics] Record exit code on expected error.

This will prevent a final segfault from sneaking by, detected as a passing test.
A more principled follow-up commit would bottleneck detected error exit
reporting and have it write something to std::cerr that can be recognized.
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
Notes versus what jsiek wrote:

- This adopts Bazel for building.
    - System-local versions of bison/flex are used. I found https://github.com/jmillikin/rules_bison, but those print a lot of warnings (things like -Wsign-compare IIRC) which makes builds hard to read. Plus I think the underlying bison_cc_library rule didn't work, so this would really only get a hermetic bison/flex build (helpful, but didn't seem worth more time).
    - I'm adding in a .bazeliskrc to push a somewhat more standard choice of bazel versions. I noticed I was getting unstable versions by default, possible Google-specific, but seemed good to include.
    - The `-lpthread` kludge.
- Turn all of the examples into golden tests.
    - Including adding a golden test rule.
- Fixed various style guide issues. For example:
    - Fixing function names to be CamelCase instead of snake_case (https://google.github.io/styleguide/cppguide.html#Function_Names)
    - Removed exception use (https://google.github.io/styleguide/cppguide.html#Exceptions)
    - File name fixes (https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/cpp_style_guide.md#file-names)
- Dropped `using` of `std` names -- I believe this is preferred (maybe we should be explicit about this in the Carbon style guide)
- Switched `enum` uses to `enum class` for ease-of-identification.
- Spent some time breaking out files to hopefully be easier to read/edit pieces, and understand relations between structs.
- Added `code requires` to `syntax.ypp` to address include issues

Possibly other things -- but the fundamental structure is, I believe, unchanged. I put in the golden tests pretty early to ensure I wasn't mutating output/results.
chandlerc pushed a commit that referenced this pull request Jun 28, 2022
* Add assertion to detect UB in interpreter.cpp

This change, applied to 6e5070d ("Adapting jsiek's executable semantics tooling
for commit. (#237)"), causes the if2.6c test to segfault.  Becase the assertion
fires only when `stmt == nullptr` and no code has permission to change `stmt`
(it is `const`) before it is dereferenced in the `switch`, and nothiing in
`PrintStatement` is supposed to exit the program, the assertion is a valid
change that detects a bug.

The crash was originally manifest in 29a5994 ("Executable Semantics: 1st-class
stacks (#296)").

* Temporarily disable the if2 test pending #311

See #311

* [executable semantics] Record exit code on expected error.

This will prevent a final segfault from sneaking by, detected as a passing test.
A more principled follow-up commit would bottleneck detected error exit
reporting and have it write something to std::cerr that can be recognized.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes PR meets CLA requirements according to bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants