Skip to content

Rebuild parser around typed OpenACC AST#20

Merged
ouankou merged 1 commit into
mainfrom
agent/typed-openacc-parser-v02
Jul 13, 2026
Merged

Rebuild parser around typed OpenACC AST#20
ouankou merged 1 commit into
mainfrom
agent/typed-openacc-parser-v02

Conversation

@ouankou

@ouankou ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

This rebuilds the parser around an owning, value-semantic OpenACC 3.4 AST and removes the late unparse/normalization behavior that previously concealed malformed frontend output.

  • introduce an explicit openacc::parseDirective API with parse options, structured diagnostics, source ranges, and no partial AST on failure
  • replace raw strings, numeric sentinels, generic clause payloads, and pointer-owned IR with clause-specific enums, variants, nonempty lists, and semantic host-fragment types
  • separate directive-envelope handling and balanced host-expression scanning from the structural ANTLR grammar
  • make the formatter a canonical, exhaustive AST consumer and compare ASTs directly for semantic equality
  • retain parseOpenACC(std::string) only as a deprecated transition wrapper
  • add focused negative, round-trip, concurrency, sanitizer, and fuzz coverage

Why

The previous pipeline allowed frontend defects to survive into the IR and then repaired their text late in the unparser. It also carried loosely typed strings and numbers through the AST, exposed mutable/global parser behavior, and could represent structurally or semantically invalid directives.

Those workarounds made successful unparsing an unreliable correctness signal: malformed ASTs could appear valid after clause merging, whitespace repair, case folding, or modifier reconstruction. This change moves validation to the parse boundary, makes invalid states harder to construct, and ensures formatting cannot mask parser errors.

Implementation details

Typed public model

  • the public API no longer exposes generated ANTLR types
  • directives and clauses own their data and use value semantics
  • clause-specific modifier types preserve the distinctions among clauses such as copyin, copyout, and create
  • device-specific clauses use explicit device-type groups
  • expression-like values are categorized as conditions, integer expressions, variable references, routine names, and related semantic roles
  • list invariants and required arguments are enforced during construction
  • parsing is reentrant and does not rely on a global clause-merging mode

Frontend and validation

  • support directive bodies, C/C++ #pragma, C/C++ _Pragma, and free/fixed-form Fortran sentinels
  • preserve host-language fragments while correctly handling nesting, comments, strings, escapes, and Fortran continuations
  • perform directive/clause compatibility, modifier, arity, uniqueness, and nonempty-list validation before returning an AST
  • report deterministic diagnostics with source ranges and return no partial directive for invalid input
  • align modifier handling with OpenACC 3.4, including the published copyout erratum

Canonical output and tests

  • format from typed AST data without reparsing or repairing raw payloads
  • use structural semantic equality for parse-format-parse checks
  • add positive and negative parser cases for malformed envelopes, balanced fragments, modifiers, clause restrictions, Fortran forms, and _Pragma
  • add concurrent parsing coverage to guard reentrancy
  • restore and migrate the 44 built-in snapshot tests to canonical typed-AST output and expected-invalid NULL rows
  • add a Clang libFuzzer target and seed corpus
  • add optional ASan/UBSan and TSan CMake configurations
  • update existing tools and compatibility tests to exercise the new API

Compatibility and impact

This is a deliberate public model/API revision. New callers should include OpenACCParser.h and use openacc::parseDirective, openacc::ParseResult, and openacc::formatDirective. The old single-string entry point remains available as a deprecated wrapper for transition, while internal constructor and generated parser types are no longer installed as public API.

The canonical formatter may normalize envelope and whitespace spelling, but semantic host fragments are preserved rather than used as an AST repair channel.

Validation

  • cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
  • full Debug regression suite: 920/920 passed
  • full ASan/UBSan regression suite: 920/920 passed
  • clean Clang 22 build with -Wall -Wextra -Wpedantic -Werror
  • focused clang-tidy checks for condition increments, vector reservation, enum size, and unnecessary value parameters
  • installed-library external consumer compiled with -Wall -Wextra -Werror and ran successfully
  • seeded libFuzzer smoke run: 5,000 runs, no crash
  • git diff --check and LLVM clang-format --dry-run --Werror clean

Specification

Semantics were reviewed against the current OpenACC 3.4 specification and its published erratum:
https://www.openacc.org/specification

@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@ouankou
ouankou marked this pull request as ready for review July 13, 2026 01:05
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99b706a7f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 99b706a to 7b36673 Compare July 13, 2026 01:59
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b36673a5f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
Comment thread tests/preprocess.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 7b36673 to 8b21b4a Compare July 13, 2026 02:20
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b21b4a1dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 8b21b4a to f583a39 Compare July 13, 2026 02:34
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

1 similar comment
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f583a39473

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from f583a39 to a125170 Compare July 13, 2026 04:15
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1251705b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from a125170 to 0ff6997 Compare July 13, 2026 04:32
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ff6997255

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/preprocess.cpp Outdated
Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 0ff6997 to 95b6602 Compare July 13, 2026 04:59
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95b6602ab0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 95b6602 to db84b70 Compare July 13, 2026 05:20
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db84b701ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from db84b70 to 60b711a Compare July 13, 2026 05:49
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60b711aab2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 60b711a to 3d11148 Compare July 13, 2026 06:17
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d11148e60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 3d11148 to 873baae Compare July 13, 2026 06:42
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 873baae699

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 873baae to 52adcfe Compare July 13, 2026 07:06
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52adcfefa6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 52adcfe to 8f65aae Compare July 13, 2026 07:43
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f65aaeb3c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/preprocess.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 8f65aae to 11a838a Compare July 13, 2026 08:10
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11a838a9e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 11a838a to e6c731e Compare July 13, 2026 08:31
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6c731e21a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp Outdated
Comment thread src/OpenACCASTConstructor.cpp Outdated
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from e6c731e to 3d65c57 Compare July 13, 2026 13:41
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d65c57dc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/OpenACCASTConstructor.cpp
@ouankou
ouankou force-pushed the agent/typed-openacc-parser-v02 branch from 3d65c57 to f4c9a31 Compare July 13, 2026 14:19
@ouankou

ouankou commented Jul 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: f4c9a31dff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ouankou
ouankou merged commit dca5634 into main Jul 13, 2026
6 checks passed
@ouankou
ouankou deleted the agent/typed-openacc-parser-v02 branch July 13, 2026 14:38
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.

1 participant