winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.06k stars 198 forks source link

fix(compiler): unexpected StripPrefixError #7146

Closed Chriscbr closed 2 months ago

Chriscbr commented 2 months ago

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

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

github-actions[bot] commented 2 months ago

Thanks for opening this pull request! :tada: 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 commented 2 months ago

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

Last Updated (UTC) 2024-09-19 19:33
monadabot commented 2 months ago

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
monadabot commented 2 months ago

Congrats! :rocket: This was released in Wing 0.85.11.