Skip to content

Commit

Permalink
Fix provisional handling for Darwin to be consistent.
Browse files Browse the repository at this point in the history
We treated things with neither "introduced" nor "provisional" annotations as
provisional in availabilityHelper(), but isProvisional() returned false for
them.  This could lead us to generate non-provisional code (conditioned on
isProvisional()) that would try to call into things with provisional
availability, which would fail to compile.

The fix is to make isProvisional the source of truth for whether things are
provisional, move the "no introduced annotation" check into isProvisional, and
factor out the "have provisional annotation" logic so we can keep having the
warning when we take the "provisional because not otherwise annotated" codepath.
  • Loading branch information
bzbarsky-apple committed Oct 27, 2023
1 parent 4084573 commit c49a77f
Showing 1 changed file with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,17 @@ async function availabilityHelper(clusterName, language, options) {
);
}

if (introducedVersions === undefined) {
const provisionalRelease = findProvisionalRelease(this.global, clusterName, options, 'provisional');
if (!provisionalRelease) {
console.log(
`WARNING: Missing "introduced" or "provisional" entry for: '${clusterName}' '${JSON.stringify(
options.hash
)}'`
);
}
}

const provisionalAvailability = (() => {
if (language == "ObjC") {
return 'MTR_PROVISIONALLY_AVAILABLE';
Expand All @@ -731,17 +742,6 @@ async function availabilityHelper(clusterName, language, options) {
return provisionalAvailability;
}

if (introducedVersions === undefined) {
console.log(
`WARNING: Missing "introduced" or "provisional" entry for: '${clusterName}' '${JSON.stringify(
options.hash
)}'`
);
// Default to provisinal status until we decide otherwise, so we don't
// accidentally ship things as unconditionally available.
return provisionalAvailability;
}

const futureAvailability = (() => {
if (language == "ObjC") {
return 'MTR_NEWLY_AVAILABLE';
Expand Down Expand Up @@ -986,31 +986,51 @@ function isSupported(cluster, options) {
return true;
}

function findProvisionalRelease(global, cluster, options) {
let provisionalRelease = findReleaseForPathOrAncestorAndSection(global, cluster, options, 'provisional');
if (provisionalRelease !== undefined) {
return provisionalRelease;
}

// For attributes, also check whether this is a provisional global
// attribute.
let attrName = options.hash.attribute;
if (!attrName) {
return undefined;
}

return findReleaseForPathOrAncestorAndSection(
global,
/* cluster does not apply to global attributes */
"",
/*
* Keep our options (e.g. in terms of isForIds bits), but replace
* attribute with globalAttribute.
*/
{ hash: { ...options.hash, attribute: undefined, globalAttribute: attrName } },
'provisional'
);
}

function isProvisional(cluster, options) {
let provisionalRelease = findReleaseForPathOrAncestorAndSection(this.global, cluster, options, 'provisional');
// Things that have no "introduced" are always provisional.
const data = fetchAvailabilityData(this.global);
let path = makeAvailabilityPath(cluster, options);
let introducedRelease = findReleaseForPath(
data,
['introduced', ...path],
options);

if (introducedRelease == undefined) {
// If it's not introduced, default to provisional.
return true;
}

let provisionalRelease = findProvisionalRelease(this.global, cluster, options);
if (provisionalRelease === undefined) {
// For attributes, also check whether this is a provisional global
// attribute.
let attrName = options.hash.attribute;
if (attrName) {
provisionalRelease = findReleaseForPathOrAncestorAndSection(
this.global,
/* cluster does not apply to global attributes */
"",
/*
* Keep our options (e.g. in terms of isForIds bits), but replace
* attribute with globalAttribute.
*/
{ hash: { ...options.hash, attribute: undefined, globalAttribute: attrName } },
'provisional'
);
}
if (provisionalRelease === undefined) {
return false;
}
return false;
}

let path = makeAvailabilityPath(cluster, options);
while (path !== undefined) {
let comparisonStatus = compareIntroductionToReferenceRelease(
this.global,
Expand Down

0 comments on commit c49a77f

Please sign in to comment.