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

feature enhancement - implement unique ID generated at compile time #138

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

winitzki
Copy link

@winitzki winitzki commented Jul 27, 2023

A "source UUID" is a unique ID generated at compile time at a given source code location. So, the value of SourceUUID depends only on the source code location and will be the same each time that code is executed.

    def generateUUIDs() = {
      val uuid1 = implicitly[sourcecode.SourceUUID].value // Generate some UUID.
      val uuid2 = implicitly[sourcecode.SourceUUID].value // This will be a different UUID.
      (uuid1, uuid2)
    }

    val (u1a, u2a) = generateUUIDs() // Generate a pair of UUIDs.
    val (u1b, u2b) = generateUUIDs() // This will be the same pair of UUID.

    assert(u1a != u2a) // Verify that the two UUIDs are different.
    assert(u1a == u1b) // The UUIDs are generated at compile time.
    assert(u2a == u2b) // So, calling `generateUUIDs()` several times will produce the same results.

Motivation for this feature is to be able to generate unique IDs at compile time for values created in a DSL. The IDs should remain unique even when values are created within a function that is being called several times. In this way, the IDs serve as unique labels on values created via DSL code.

@winitzki
Copy link
Author

FYI - I am not able to run tests on my laptop because the command mill -i all __.test fails with:

Mill version 0.11.1 is different than configured for this directory!
Configured version is 0.10.12 (/Users/sergei.winitzki/Code/sourcecode/.mill-version)
[build.sc] [41/49] compile
[info] compiling 1 Scala source to /Users/sergei.winitzki/Code/sourcecode/out/mill-build/compile.dest/classes ...
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:6:26: object Util is not a member of package mill.scalalib.api
[error] import mill.scalalib.api.Util.isScala3
[error]                          ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:30:8: not found: value isScala3
[error]     if(isScala3(crossScalaVersion)) Agg.empty[Dep] else super.mimaPreviousArtifacts()
[error]        ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:75:11: not found: value CrossModuleBase
[error]       .++(CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => millSourcePath / s"src-$s" ))
[error]           ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:87:49: type mismatch;
[error]  found   : List[String]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.JvmSourcecodeModule]]
[error]   object jvm extends Cross[JvmSourcecodeModule](scalaVersions: _*)
[error]                                                 ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:98:47: type mismatch;
[error]  found   : List[(String, String)]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.JsSourcecodeModule]]
[error]   object js extends Cross[JsSourcecodeModule](scalaJSVersions: _*)
[error]                                               ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:113:55: type mismatch;
[error]  found   : List[(String, String)]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.NativeSourcecodeModule]]
[error]   object native extends Cross[NativeSourcecodeModule](scalaNativeVersions: _*)
[error]                                                       ^
[error] 6 errors found
1 targets failed
compile Compilation failed

I have tried to set MILL_VERSION=0.10.12 but I still get the same error.

The CI doesn't seem to run on this PR automatically either. I'm not sure how to proceed, please help.

@winitzki winitzki changed the title implement SourceUUIDs feature enhancement - implement SourceUUIDs Jul 27, 2023
@lefou
Copy link
Member

lefou commented Jul 27, 2023

FYI - I am not able to run tests on my laptop because the command mill -i all __.test fails with:

Mill version 0.11.1 is different than configured for this directory!
Configured version is 0.10.12 (/Users/sergei.winitzki/Code/sourcecode/.mill-version)
[build.sc] [41/49] compile
[info] compiling 1 Scala source to /Users/sergei.winitzki/Code/sourcecode/out/mill-build/compile.dest/classes ...
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:6:26: object Util is not a member of package mill.scalalib.api
[error] import mill.scalalib.api.Util.isScala3
[error]                          ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:30:8: not found: value isScala3
[error]     if(isScala3(crossScalaVersion)) Agg.empty[Dep] else super.mimaPreviousArtifacts()
[error]        ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:75:11: not found: value CrossModuleBase
[error]       .++(CrossModuleBase.scalaVersionPaths(crossScalaVersion, s => millSourcePath / s"src-$s" ))
[error]           ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:87:49: type mismatch;
[error]  found   : List[String]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.JvmSourcecodeModule]]
[error]   object jvm extends Cross[JvmSourcecodeModule](scalaVersions: _*)
[error]                                                 ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:98:47: type mismatch;
[error]  found   : List[(String, String)]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.JsSourcecodeModule]]
[error]   object js extends Cross[JsSourcecodeModule](scalaJSVersions: _*)
[error]                                               ^
[error] /Users/sergei.winitzki/Code/sourcecode/build.sc:113:55: type mismatch;
[error]  found   : List[(String, String)]
[error]  required: Seq[mill.define.Cross.Factory[millbuild.build.sourcecode.NativeSourcecodeModule]]
[error]   object native extends Cross[NativeSourcecodeModule](scalaNativeVersions: _*)
[error]                                                       ^
[error] 6 errors found
1 targets failed
compile Compilation failed

I have tried to set MILL_VERSION=0.10.12 but I still get the same error.

The CI doesn't seem to run on this PR automatically either. I'm not sure how to proceed, please help.

looks like you're using the mill-assembly jar directly (which is supposed to be downloaded and used by the scripts), instead of a mill script (either to official mill script or millw).

@winitzki
Copy link
Author

I did brew install mill, as per the official instructions for installing mill on a Mac. How else should I install mill on a Mac?

@winitzki winitzki changed the title feature enhancement - implement SourceUUIDs feature enhancement - implement unique ID generated at compile time Jul 28, 2023
@winitzki
Copy link
Author

winitzki commented Jul 28, 2023

Finally I figured out that I should have run ./mill instead of mill. This is confusing.

Tests pass now on my local machine.

@lefou
Copy link
Member

lefou commented Jul 28, 2023

Looks like brew is not the best way to install Mill then. I opened issue com-lihaoyi/mill#2674. Instead of brew, you can just install the mill script into your bin directory. See also https://mill-build.com/mill/Installation_IDE_Support.html#_bootstrap_scripts. My personal recommendation is to use millw, as it supports almost all legacy Mill versions and has also a script for Windows.

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