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

fix(compiler): unexpected StripPrefixError #7146

Merged
merged 4 commits into from
Sep 19, 2024
Merged

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Sep 19, 2024

Fixes a bug where the compiler can panic in certain situations when files from different directories are loaded. Specifically, the issue happens when a Wing file tries importing another Wing file from a directory that is not a sibling or in a sibling directory.

The issue is related to a facility of the compiler responsible for calculating a FQN (fully-qualified name) for every public type. To calculate the FQN for a public type like a class, we need to know where the file is relative to its package. For example, when a file like /home/node_modules/@winglibs/dynamodb/aws/table.w is type checked, the compiler needs to know that it belongs to the library named @winglibs/dynamodb and that the root of @winglibs/dynamodb is /home/node_modules/@winglibs/dynamodb. This way, types defined inside aws will get added to the aws namespace, and types defined at the root should get added to the root namespace, and if a type is defined outside of the project root, it's an error.

Today, the way we identify what package each source file belongs to is by looking up the file system and seeing if there's a package.json or wing.toml file somewhere up the file tree. But we don't enforce all projects to have these files and we want the language server to work even when these files don't exist. In such cases, we decide that all files that aren't part of a well-defined package are part of an implicit "default" package, and the root of this default package is whatever is the common root of all of its files.

This PR should also slightly improve the stability of the language server.

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • Tests added (always)
  • Docs updated (only required for features)
  • Added pr/e2e-full label if this feature requires end-to-end testing

By submitting this pull request, I confirm that my contribution is made under the terms of the Wing Cloud Contribution License.

@Chriscbr Chriscbr requested a review from a team as a code owner September 19, 2024 18:55
Copy link

Thanks for opening this pull request! 🎉
Please consult the contributing guidelines for details on how to contribute to this project.
If you need any assistance, don't hesitate to ping the relevant owner over Discord.

Topic Owner
Wing SDK and standard library @chriscbr
Wing Console @skyrpex
Wing compiler and language design @chriscbr
VSCode extension and language server @chriscbr
Wing CLI @chriscbr
Documentation @boyney123
Examples @boyney123
Wing Playground @skyrpex

@monadabot
Copy link
Contributor

monadabot commented Sep 19, 2024

Console preview environment is available at https://wing-console-pr-7146.fly.dev 🚀

Last Updated (UTC) 2024-09-19 19:33

@monadabot
Copy link
Contributor

monadabot commented Sep 19, 2024

Benchmarks

Comparison to Baseline ⬜⬜⬜⬜⬜⬜⬜⬜⬜🟥⬜⬜⬜
Benchmark Before After Change
version 58ms±0.55 58ms±0.72 +0ms (+0.76%)⬜
hello_world.test.w -t sim 419ms±4.22 431ms±13.44 +12ms (+2.74%)⬜
hello_world.test.w -t tf-aws 1531ms±15.37 1542ms±12.18 +11ms (+0.74%)⬜
jsii_small.test.w -t sim 394ms±9.24 395ms±7.27 +1ms (+0.25%)⬜
jsii_small.test.w -t tf-aws 629ms±7.06 627ms±6.17 -1ms (-0.2%)⬜
jsii_big.test.w -t sim 3093ms±21.22 3100ms±13.74 +8ms (+0.24%)⬜
jsii_big.test.w -t tf-aws 3308ms±11.95 3307ms±12.65 -1ms (-0.02%)⬜
empty.test.w -t sim 385ms±4.12 385ms±4.18 +1ms (+0.15%)⬜
empty.test.w -t tf-aws 610ms±4.41 625ms±5.53 +15ms (+2.53%)⬜
functions_10.test.w -t sim 501ms±16.02 530ms±14.62 +30ms (+5.95%)🟥
functions_10.test.w -t tf-aws 2227ms±30.99 2274ms±21.29 +48ms (+2.14%)⬜
functions_1.test.w -t sim 417ms±5.13 428ms±4.46 +12ms (+2.78%)⬜
functions_1.test.w -t tf-aws 862ms±6.1 880ms±4.04 +18ms (+2.12%)⬜

⬜ Within 1.5 standard deviations
🟩 Faster, Above 1.5 standard deviations
🟥 Slower, Above 1.5 standard deviations

Benchmarks may vary outside of normal expectations, especially when running in GitHub Actions CI.

Results
name mean min max moe sd
version 58ms 57ms 60ms 1ms 1ms
hello_world.test.w -t sim 431ms 411ms 476ms 13ms 19ms
hello_world.test.w -t tf-aws 1542ms 1522ms 1572ms 12ms 17ms
jsii_small.test.w -t sim 395ms 387ms 422ms 7ms 10ms
jsii_small.test.w -t tf-aws 627ms 613ms 639ms 6ms 9ms
jsii_big.test.w -t sim 3100ms 3070ms 3134ms 14ms 19ms
jsii_big.test.w -t tf-aws 3307ms 3287ms 3333ms 13ms 18ms
empty.test.w -t sim 385ms 376ms 395ms 4ms 6ms
empty.test.w -t tf-aws 625ms 616ms 638ms 6ms 8ms
functions_10.test.w -t sim 530ms 492ms 561ms 15ms 20ms
functions_10.test.w -t tf-aws 2274ms 2220ms 2317ms 21ms 30ms
functions_1.test.w -t sim 428ms 420ms 439ms 4ms 6ms
functions_1.test.w -t tf-aws 880ms 871ms 888ms 4ms 6ms
Last Updated (UTC) 2024-09-19 19:38

@Chriscbr Chriscbr merged commit 9d49fce into main Sep 19, 2024
23 checks passed
@Chriscbr Chriscbr deleted the rybickic/fix-prefix-error branch September 19, 2024 20:14
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.85.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants