Comments (5)
This is an intriguing idea. I think as long as we add a way to explicitly silence the warning (like an attribute) at the same time, such warnings would be useful
from chapel.
But it also made me want to check whether you're proposing eliminating defaults for all params, or just fields.
I'm only proposing removing the default for param fields in user-defined initializers here.
Presumably the second case would still work, and we'd want it to, and the first would still be an error, just a different kind of error? So what inconsistency is getting resolved?
Hmm. I think you're right, at least re-reading my comment leaves me wondering the same thing.
So what's the inconsistency? It's that we consider param p: int
to have a default in some initializer settings but not others:
- it does not have a default as a formal for the type constructor
- it does not have a default as a formal for the compiler-generated default initializer
- it does have a default in a user-defined initializer.
If we make it not have a default for the user-defined initializer, these become consistent; we can say that a field param p: int
is not considered to have a default. That would make it more consistent with type
fields, which appeals to me because I consider param
to be closer to type
than to var
/const
/etc.
from chapel.
Yeah, I agree we'd want a way to opt-out (as with all warnings).
from chapel.
IMO it does not make sense to have a param
field use a default value when one is not specified (i.e., 0
for integers). Adding a warning for the initializer above that does not initialize rank
would certainly be OK with me, but I have a slight preference for going further and making this case an error.
Today, param
fields don't work the same as if they have the zero default value:
record R {
param p: int;
}
var x: R; // warning: please use '?' when declaring a variable with generic type
// error: cannot default-initialize a variable with generic type
writeln(x);
record R {
param p: int = 0;
}
var x: R; // OK
writeln(x); // prints ()
Making it the initializer not setting this.rank
into an error would resolve this inconsistency.
On this point, the spec says this:
In order to support productive and elegant initializers, the language allows field initializations to be omitted if the field has a type or if the field has an initialization expression. The compiler will insert initialization statements for such fields based on their types and default values.
So, the spec matches the current behavior. However, IMO, the "field has a type" rule should only apply to non-param non-type fields.
from chapel.
@mppf: I think I'm open to your stronger proposal, though I'm not quite understanding your statement that the change would resolve the inconsistency (or maybe I don't understand what the inconsistency is?). Presumably the second case would still work, and we'd want it to, and the first would still be an error, just a different kind of error? So what inconsistency is getting resolved?
The only slight hesitancy I have about the approach is that I like that non-field param count: int;
or config param count: int;
default to 0 (for consistency with var
and const
), so am slightly uneasy about adding an inconsistency between fields and non-fields in this regard. But I think I'm more worried about the confusion I hit than I am about that inconsistency.
But it also made me want to check whether you're proposing eliminating defaults for all params, or just fields.
from chapel.
Related Issues (20)
- [Documentation]: Extend the Standard Module Style guide for other decisions we've made HOT 1
- [Bug]: Subprocesses interact strangely with `valgrind`
- Type Promotion Issue with Complex Types HOT 3
- Should forall loops over default arrays of locales result in coforall + on implementation by default? HOT 4
- Simplify/specialize error message for calling a method on a nilable class variable HOT 2
- Dyno asserts when casting a param string to bytes HOT 2
- Make test config scripts consistent when sourcing other files HOT 1
- Should we support a low memory sort option HOT 1
- How should `proc sort` handle non-1D/non-rectangular arrays HOT 3
- [Bug]: Rexported symbols like `sqrt` cause issues when imported using `.{..}` HOT 4
- chpl__init_ModuleName(int64_t _ln, int32_t _fn) has mystery parameters HOT 1
- should identifier matches against the enclosing module name be considered if there are other matches? HOT 6
- Performance delta between Chapel and CUDA for `tanh` HOT 2
- `make test-cls` fails in quickstart config on M1 mac
- [Documentation]: Improve GPU Setup Documentation for CHPL_LOCALE_MODEL=gpu
- Standalone Arkouda `ContrivedConstructor` caused compiler to throw unreasonable promotion/parameness error HOT 1
- [Feature Request]: Chapel OS packages with GPU support
- Add chpl-language-server documentation for vim and emacs HOT 4
- [Bug]: problems in LLVM or C codegen
- [Documentation]: Should we move the documentation on syntax highlighting into the online documentation?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chapel.