19201, "arezaii", "How to add a non-param type similar to 'sourceVersion' ", "2022-02-07T19:10:23Z"
Overview
Should the Version
module include a type that can be built during runtime in addition to the sourceVersion
type that only supports params? For context, the original discussion regarding the Version
module is https://github.com/chapel-lang/chapel/issues/15911.
During the module review of the Version
module we discussed a need for mason
to support a type that describes a software version.
mason
needs this type to reason about different dependency versions. These versions are never known at compile time, so the current sourceVersion
type doesn't meet the needs and mason
implements a custom type which essentially replicates the functionality found in the sourceVersion
type.
We would like to answer some questions about how this support could be implemented.
One type, or two types?
One type may be easier to maintain, but two types could clearly express the use case for each type by giving each a descriptive name.
If two types, where do they live and what do we name them?
Do we expect both types would live in the Version
module?
Some naming options that were suggested during module review are:
Param version:
sourceVersion
Non-param version:
runtimeVersion
If one type, how does a user specify the param/non-param version?
One option might be to change the member variables to const
and provide two different constructors, one param and one non-param.
Implementation might look like the following:
record sourceVersion {
const major:int;
const minor:int;
const update:int;
const commit:string;
proc init(major:int, minor:int, update:int, commit="") {
this.major = major;
this.minor = minor;
this.update = update;
this.commit = commit;
}
proc init(param major:int, param minor:int, param update:int, param commit="") {
this.major = major;
this.minor = minor;
this.update = update;
this.commit = commit;
}
...
}
We could also overload the createVersion
proc with a new non-param version, something like:
proc createVersion(param major: int,
param minor: int,
param update: int = 0,
param commit: string = ""): sourceVersion {
return new sourceVersion(major, minor, update, commit);
}
proc createVersion(major: int,
minor: int,
update: int = 0,
commit: string = ""): sourceVersion {
return new sourceVersion(major, minor, update, commit);
}
This would give the user the flexibility to instantiate a new sourceVersion
four ways:
// where vars major, minor, update, and commit are set at runtime
const runtimeVer = createVersion(major, minor, update, commit);
const paramVer = createVersion(1,2,3);
//OR
const runtimeVer = new sourceVersion(major, minor, update, commit);
const paramVer = new sourceVersion(1,2,3);
Comments on these proposals and other suggestions/proposals are encouraged, thanks!