-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experiment: deprecate experimental stable memory (improved) (#4575)
Leverages `/// @deprecate` comments to deprecate uses of ExperimentalStableMemory. Adds moc flag `--experimental-stable-memory <n>` to control access to legacy stable memory: - n<0: error on use of (ESM) prims. - n=0: warn on use of prims. - n=1: warning-less use of prims. Current default is n=0 to encourage users to migrate their code to use preferred `Region.mo` without preventing compilation. The implementation adds /// @deprecate M0199 comments Prim.mo and spots this specific deprecation during type-checking, reporting this specific violation just once per compilation unit, as an error, warning or not at all, depending on compiler setting. The net effect is that, by default, any code that directly or indirectly imports ESM will be reported, as will any code that directly access a stable memory primitive, alerting the user to potential vulnerabilities. The code will still compile, but in future we can prevent that by defaulting n to 0, not 1. The not-so-nice aspect of this implementation is that: 1: The errors only indicate that ESM *may* be in use. 2: They do not pinpoint which importing library is responsible for the warning, but adding `/// @deprecate M0199` to corresponding ESM fields directly should achieve that too.
- Loading branch information
Showing
74 changed files
with
260 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# M0199 | ||
|
||
This error or warning means that your code is either directly or indirectly using the now deprecated library `ExperimentalStableMemory.mo` (or its supporting compiler primitives). | ||
|
||
The library works as advertised but is a potential hazard as the resource it provides access to is shared between all clients of the library. | ||
This means that a library may unintentionally or maliciously read or modify data maintained by your application, or by another library imported by your application. | ||
|
||
If possible, please upgrade your code to use library `Region.mo` instead. | ||
This improved library offers a similar abstraction, but instead of a single memory that is implicitly accessible to all callers, it provides multiple memories. | ||
These memories, called regions, are isolated from each other and inaccessible unless a region is explicitly shared between libraries. | ||
|
||
The `moc` compiler flag `--experimental-stable-memory <n>` flag controls the production of this error or warning message, allowing your code to compile as before: | ||
* n < 0: error on use of stable memory primitives. | ||
* n = 0: warn on use of stable memory primitives (the default). | ||
* n > 1: warning-less use of stable memory primitives (for legacy applications). | ||
|
||
I.e. if your application cannot easily be upgraded to use `Regions.mo` and still requires access to `ExperimentalStableMemory.mo`, you can opt-in to legacy support for `ExperimentalStableMemory.mo` using the `moc` compiler flag `--experimental-stable-memory 1`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
region0-mem.mo:7.4-7.27: warning [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
stable-mem.mo:7.4-7.27: warning [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//MOC-FLAG --experimental-stable-memory -1 | ||
import P "mo:⛔"; | ||
|
||
import {stableMemoryGrow= _} "mo:⛔"; | ||
actor { | ||
|
||
let _ = P.stableMemorySize; | ||
} | ||
|
||
//SKIP run | ||
//SKIP run-low | ||
//SKIP run-ir | ||
// too slow on ic-ref-run: | ||
//SKIP comp-ref | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//MOC-FLAG --experimental-stable-memory 0 | ||
import P "mo:⛔"; | ||
|
||
import {stableMemoryGrow= _} "mo:⛔"; | ||
actor { | ||
|
||
let _ = P.stableMemorySize; | ||
} | ||
|
||
//SKIP run | ||
//SKIP run-low | ||
//SKIP run-ir | ||
// too slow on ic-ref-run: | ||
//SKIP comp-ref | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//MOC-FLAG --experimental-stable-memory 1 | ||
import P "mo:⛔"; | ||
|
||
import {stableMemoryGrow= _} "mo:⛔"; | ||
actor { | ||
|
||
let _ = P.stableMemorySize; | ||
} | ||
|
||
//SKIP run | ||
//SKIP run-low | ||
//SKIP run-ir | ||
// too slow on ic-ref-run: | ||
//SKIP comp-ref | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
experimental-stable-memory--1.mo:4.9-4.28: type error [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
ingress Completed: Reply: 0x4449444c0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
experimental-stable-memory-0.mo:4.9-4.28: warning [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
ingress Completed: Reply: 0x4449444c0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gc-random-test/types.mo:301.20-301.41: warning [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gc-random-test/types.mo:301.20-301.41: warning [M0199], this code is (or uses) the deprecated library `ExperimentalStableMemory`. | ||
Please use the `Region` library instead: https://internetcomputer.org/docs/current/motoko/main/stable-memory/stable-regions/#the-region-library or compile with flag `--experimental-stable-memory 1` to suppress this message. |
Oops, something went wrong.