Skip to content

feat[cartesian]: Remove redundant region syntax#2554

Merged
twicki merged 7 commits intoGridTools:mainfrom
twicki:remove_redundant_syntax
Mar 27, 2026
Merged

feat[cartesian]: Remove redundant region syntax#2554
twicki merged 7 commits intoGridTools:mainfrom
twicki:remove_redundant_syntax

Conversation

@twicki
Copy link
Copy Markdown
Contributor

@twicki twicki commented Mar 26, 2026

Series on interval-parsing (3/3)

This PR is one in a series to simplify interval parsing in the front-end.

This entire series was triggered, because runtime-intervals and higher dimensional fields do not interact as intended right now. So here the summary of the slate of work

Current State:

  • The parser between horizontal and vertical intervals is shared
    • This leads to a lot of differentiation having to happen in the calls since what is and is not allowed is very different
  • There is a plethora of different syntaxes allowed for vertical intervals
  • With runtime-intervals now being part of the equation, differentiation became even harder.
  • Accessing higher-dimensional fields with []-operators did trigger exceptions

To tackle these problems, the following PR's are up:

2510: split the parser for the horizontal and the vertical and specialize them as appropriate
2553: fix how runtime-intervals interact with higher dimensional fields
current: remove all redundant syntax to go back to a more specific language

Description

The legal syntax for regions was very bloated and allowed for multiple ways to express a single output. This PR trims this down to a more minimalistic approach.
Previously allowed:

  • I[0:2]
  • I[0] : I[2]
  • I[0] : I[0] + 2
  • 0:2

There is no clean way to completely avoiding the axis-access syntax, as it is required to generate somewhat clean out-of-domain computations to skip by going I[0]- LARGENUMBER. this is why axis-access is still allowed additionally to plain offset syntax. but only to access the start and end of the domain.

So this PR minimizes the syntax down to

  • I[0] : I[0] + 2
  • 0:2

@twicki twicki requested a review from romanc March 26, 2026 11:24
Copy link
Copy Markdown
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

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

Some remaining test failures, otherwise looking good to me. I guess there are a couple tests remaining that still use the now forbidden syntax.

):
raise GTScriptSyntaxError(
"Invalid horizontal range specification:"
f"Expected specification {self.axis_name}[0] or {self.axis_name}[-1]."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't understand why there this exception to allow I[-1]? What is different about -1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

so the goal is to allow to access both ends of the domain. The way this was previously done was with "standard" slicing notation, so I[-1] is the end of the I-domain. That way you can offset from both sides without having to know the domain-size.

And because we're still in AST-land here, -1 is not resolved into a negative constant but it is a unary-up with the value 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see - all good then.

):
raise GTScriptSyntaxError(
"Invalid horizontal range specification:"
f"Expected specification {self.axis_name}[0] or {self.axis_name}[-1]."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see - all good then.

@twicki twicki merged commit ab32fda into GridTools:main Mar 27, 2026
20 checks passed
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.

2 participants