Skip to content

Parser: fix ambiguity with whitespace in version ranges#40344

Merged
haampie merged 8 commits intospack:developfrom
haampie:fix/parser-ambiguity
Nov 1, 2023
Merged

Parser: fix ambiguity with whitespace in version ranges#40344
haampie merged 8 commits intospack:developfrom
haampie:fix/parser-ambiguity

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Oct 6, 2023

Fixes #40342

This is a breaking change, but imho develop is broken, so it's rather a bugfix.

Allowing white space around : in version ranges introduces an ambiguity:

a@1: b

parses as a@1:b but should really be parsed as two separate specs a@1: and b.

With white space disallowed around : in ranges, the ambiguity is resolved.


White space is still allowed around the , separator in version lists, since there we unambiguously require a next version/range token anyways, and in fact the syntax with whitespaces around , is used in a bunch of packages.


Apart from that, there's this rather odd, supported syntax:

a@1:b = c

It's parsed as [a, @1:, b=c]. Apparently this syntax is relied on in exactly one package -- I think disallowing that would have made sense if it wasn't relied on... I've left this as is, and added an additional test for this syntax.

Allowing white space introduces an ambiguity:

```
spack spec a@1: b
```

parses as `a@1:b` but should be parsed as two separate specs `a@1:` and `b`
@spackbot-app spackbot-app bot added core PR affects Spack core functionality tests General test capability(ies) labels Oct 6, 2023
@haampie haampie force-pushed the fix/parser-ambiguity branch from 848aeb9 to fb43645 Compare October 6, 2023 08:47
Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

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

LGTM. Only a minor request.

@haampie haampie force-pushed the fix/parser-ambiguity branch from d0529a2 to 55ab8ca Compare October 7, 2023 08:56
@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Oct 7, 2023

Apparently this syntax is relied on in exactly one package

Which package relies on this?

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 8, 2023

depends_on("py-setuptools", type="build")
depends_on(
"py-typing-extensions@3.7.4.1:4.4", type=("build", "run"), when="@1.1.2:^python@:3.7"
)
depends_on("py-colorama@0.4.6:", type=("build", "run"), when="@1.1.2:platform=windows")

Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

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

LGTM, but let's wait for at least another ✔️ for the breaking change.

Copy link
Copy Markdown
Member

@becker33 becker33 left a comment

Choose a reason for hiding this comment

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

Can you add this detail to the comment at the top of lib/spack/spack/parser.py? I think that's the only relevant documentation to update.

Copy link
Copy Markdown
Member

@tgamblin tgamblin left a comment

Choose a reason for hiding this comment

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

Since this is breaking anyway I don't think it's unreasonable to not support the py-wasabi case. We generally require a space to differentiate key-value pairs in other places... I don't see why we shouldn't also require it after a version range.

so, disallow:

a@1:b = c

and require this space:

a@1: b = c
    ^

Or do folks object?

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 9, 2023

These are all valid:

  • @1:^python
  • @:2, 4%gcc
  • build_system = makefile%gcc

Maybe % and ^ are visually good enough separators, but to me it feels like it's all not very consistent, and disallowing a@1:b=c should also mean disallowing all of the above, and that will certainly make it more likely that user repos break

All whitespace in verison specifiers should've been banned from the start ;p

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Oct 9, 2023

I don’t think it’s inconsistent. In other places we change context based on sigils, and require space for kvp’s (which start with an identifier). This is just (I think?) the only place where there is a word boundary because of a colon at the end of the thing before a kvp.

OTOH, if there is no need to disable support for it (does it introduce ambiguity or just weirdness?) then it could stay like it is.

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 10, 2023

It's not ambiguous, @1:a=b cannot be parsed as [@1:a, =b]

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 10, 2023

Can you add this detail to the comment at the top of lib/spack/spack/parser.py? I think that's the only relevant documentation to update.

What do you want to add exactly? Those high-level rules are generally unclear about use of white space, as I read them they're even more strict than what we allow, but it's hard to follow since it's not valid EBNF. I think the implementation + tests are the only correct documentation

@haampie haampie requested review from becker33 and tgamblin October 12, 2023 10:40
@haampie haampie added this to the v0.21.0 milestone Oct 17, 2023
@tgamblin
Copy link
Copy Markdown
Member

@haampie: I think my concerns are addressed by the conversation but we're still waiting on @becker33's.

@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 30, 2023

Ping @becker33

1 similar comment
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Nov 1, 2023

Ping @becker33

@haampie haampie dismissed becker33’s stale review November 1, 2023 08:08

2 approvals should be enough

@haampie haampie merged commit ac976a4 into spack:develop Nov 1, 2023
@haampie haampie deleted the fix/parser-ambiguity branch November 1, 2023 08:09
gabrielctn pushed a commit to gabrielctn/spack that referenced this pull request Nov 24, 2023
Allowing white space around `:` in version ranges introduces an ambiguity:

```
a@1: b
```

parses as `a@1:b` but should really be parsed as two separate specs `a@1:` and `b`.

With white space disallowed around `:` in ranges, the ambiguity is resolved.
mtaillefumier pushed a commit to mtaillefumier/spack that referenced this pull request Dec 14, 2023
Allowing white space around `:` in version ranges introduces an ambiguity:

```
a@1: b
```

parses as `a@1:b` but should really be parsed as two separate specs `a@1:` and `b`.

With white space disallowed around `:` in ranges, the ambiguity is resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR affects Spack core functionality tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spack add parser: Unbounded version specifier followed by another spec

4 participants