Skip to content

[hyperactor] attribute defaults #233

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

Closed
wants to merge 5 commits into from

Conversation

mariusae
Copy link
Member

@mariusae mariusae commented Jun 11, 2025

Stack from ghstack (oldest at bottom):

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling contains_key.

Along with this, we implement Index and IndexMut, allowing a natural syntax:

declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: D76438138

NOTE FOR REVIEWERS: This PR has internal Meta-specific changes or comments, please review them on Phabricator!

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

[ghstack-poisoned]
mariusae added a commit that referenced this pull request Jun 11, 2025
An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

ghstack-source-id: 289709203
Pull Request resolved: #233
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 11, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76438138

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

[ghstack-poisoned]
mariusae added a commit that referenced this pull request Jun 11, 2025
Pull Request resolved: #233

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!
ghstack-source-id: 289710685
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76438138

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

[ghstack-poisoned]
mariusae added a commit that referenced this pull request Jun 11, 2025
Pull Request resolved: #233

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.
ghstack-source-id: 289712267

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76438138

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

[ghstack-poisoned]
mariusae added a commit that referenced this pull request Jun 11, 2025
Pull Request resolved: #233

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.
ghstack-source-id: 289754395

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76438138

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!

[ghstack-poisoned]
mariusae added a commit that referenced this pull request Jun 13, 2025
Pull Request resolved: #233

An attribute with a default returns the default value whenever an attribute does not exist in a dictionary. A caller can distinguish between a default and a set value by calling `contains_key`.

Along with this, we implement `Index` and `IndexMut`, allowing a natural syntax:

```
declare_attrs! {
  /// My key.
  pub attr MY_KEY: u64 = 1;
}

let attrs = Attrs::new();
assert_eq!(attrs[MY_KEY], 1);
attrs[MY_KEY] = 2;
assert_eq!(attrs[MY_KEY], 2);
```

With this, we can now simplify configs to maintaining a global attribute dictionary, and populating this by default from environment variables.
ghstack-source-id: 290144041

Differential Revision: [D76438138](https://our.internmc.facebook.com/intern/diff/D76438138/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D76438138/)!
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D76438138

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 45860ad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants